none
Retrieve a list of installed software base through a specified date RRS feed

  • Question

  • Greetings,

    I'm new to using powershell. I'm trying to come up with a script that retrieve a list of  software installed after the 25/5/2010. I can't seem to parse the $_datetime string correctly into the function that I've written. Would anyone be so kind to review my code? Thanks!

    function DateStringToDateTime( [String] $installDate )
    {
        $datetime = [datetime]::ParseExact($installDate, "yyyyMMdd",$null)
        return New-Object -TypeName DateTime
    }

    $formatCutOffDate = "25/05/2010"
    $cutOffDate = [datetime]::ParseExact($formatCutOffDate, "dd/MM/yyyy",$null)

    $installed32bit = Get-ChildItem  "HKLM:\software\Microsoft\Windows\CurrentVersion\Uninstall" | Where-Object {(DateStringToDateTime($_.installDate)) -ge $cutOffDate}


    Foreach ($product in $installed32bit){

        get-itemproperty registry::$product | Format-list

    }

    if($env:Processor_Architecture -eq "AMD64"){

    $installed64bit = Get-ChildItem "HKLM:\software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | where-object {(DateStringToDateTime($_.installDate)) -ge $cutOffDate }

        Foreach ($product in $installed64bit){

        get-itemproperty registry::$product | Format-list

    }

    }

    • Edited by networkted Wednesday, May 26, 2010 4:56 PM
    Wednesday, May 26, 2010 1:50 PM

Answers

  • In simple oneliner

    Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {  ([datetime]::ParseExact($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate

    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {  ([datetime]::ParseExact($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate

     There will be some nodes with no InstallDate property. You need to skip them. Otherwise the above code will generate errors like

    Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
    At line:1 char:120
    + Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {  ([datetime]::ParseExa
    ct <<<< ($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook
    • Marked as answer by networkted Thursday, May 27, 2010 3:00 AM
    • Unmarked as answer by networkted Thursday, May 27, 2010 3:18 AM
    • Marked as answer by networkted Thursday, May 27, 2010 5:51 AM
    Thursday, May 27, 2010 2:42 AM

All replies

  • Hi;

    Is there a question?

    Karl


    http://unlockpowershell.wordpress.com
    Email me@ [regex]::Matches("107097114108109105116115099104107101064109116046110101116",'(.{3})')|%{$m+=[char][int]$_.value};$m
    Wednesday, May 26, 2010 4:48 PM
  • Hi;

    Is there a question?

    Karl


    http://unlockpowershell.wordpress.com
    Email me@ [regex]::Matches("107097114108109105116115099104107101064109116046110101116",'(.{3})')|%{$m+=[char][int]$_.value};$m

    oops! sorry... I replaced my question while pasting my code
    Thursday, May 27, 2010 12:20 AM
  • When I try something like this:

    PS> Get-ChildItem  "HKLM:\software\Microsoft\Windows\CurrentVersion\Uninstall"|select -first 1|format-list *

    I don't see an "InstallDate" property so you can't use $_.InstallDate to compare the dates.

    Thursday, May 27, 2010 1:58 AM
    Moderator
  • hi Macro, thank you for your response

    Get-ChildItem  "HKLM:\software\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty

    how do I compare base on itemproperty values for installdate? thanks!

    Thursday, May 27, 2010 2:26 AM
  • You need to use Get-ItemProperty. Get-ChildItem will return only the keys and not the properties underneath.

    Get-ItemProperty  "HKLM:\software\Microsoft\Windows\CurrentVersion\Uninstall\*" | % { $_.InstallDate }


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook
    Thursday, May 27, 2010 2:32 AM
  • In simple oneliner

    Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {  ([datetime]::ParseExact($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate

    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {  ([datetime]::ParseExact($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate

     There will be some nodes with no InstallDate property. You need to skip them. Otherwise the above code will generate errors like

    Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
    At line:1 char:120
    + Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {  ([datetime]::ParseExa
    ct <<<< ($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook
    • Marked as answer by networkted Thursday, May 27, 2010 3:00 AM
    • Unmarked as answer by networkted Thursday, May 27, 2010 3:18 AM
    • Marked as answer by networkted Thursday, May 27, 2010 5:51 AM
    Thursday, May 27, 2010 2:42 AM
  • thanks for the fix! I added this condition but..it's not right..any ideas?

    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {(($_.installdate).length) -gt 1} | Where-Object {([datetime]::ParseExact($_.installDate, "yyyyMMdd",$null)) -ge $cutoffDate } | ft DisplayName, InstallDate

     

    I get errors like Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." when there's no value in $_Installdate

    Thursday, May 27, 2010 3:00 AM
  • On my system, when I run this, I see some products withno install date and some products with install date in the form of yyyy/mm/dd. So, for the products with a difference in date format the date conversion will fail since the format specifier in the code is yyyymmdd.

    You can verify that by running

    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ft installDate, DisplayName


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook
    Thursday, May 27, 2010 4:56 AM
  • On my system, when I run this, I see some products withno install date and some products with install date in the form of yyyy/mm/dd. So, for the products with a difference in date format the date conversion will fail since the format specifier in the code is yyyymmdd.

    You can verify that by running

    Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ft installDate, DisplayName


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook

    Is there any other way to get this done? I think I've issues with a different date format...
    Thursday, May 27, 2010 5:50 AM
  • Instead of checking the registry, can you use WMI to retrieve list of installed products?

    get-wmiobject Win32_product | select Name, InstallDate

    at least the property InstallDate is always filled out and formatted as YYYYmmdd

    /Dung

     

    Friday, May 28, 2010 1:10 AM
  • I think there isn't a perfect solution, WMI only works for software installed via MSI installer.
    Friday, May 28, 2010 1:42 AM