none
Building A Script through WMI to Find Software RRS feed

  • Question

  • Hello,

    My goal is to build a few scripts using Powershell, and unfortunately using WMI, to find all software that has been installed in the past two weeks, including the date installed, and then outputting that information to log file.

    I know how to find software and the date it was installed using:

    "Get-WmiObject -Class | Format-Table -Property Name,InstallDate"

    I just don't know how to filter for any software installed in the last two weeks.

    I also need to find all software that needs to be installed but has to yet, so any suggestions for either one of these would be killer.

    Thanks all.

    • Moved by Bill_Stewart Monday, July 29, 2019 8:03 PM This is not "scripts on demand"
    Saturday, January 12, 2019 8:37 PM

All replies

  • Start with "help Get-WmiObject -ShowWindow"

    Look at the filter parameter and the examples.


    \_(ツ)_/

    Saturday, January 12, 2019 9:30 PM
  • Try something like this:

    $Path = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
    $Today = (Get-Date)
    $StartDate = $today.AddDays(-14)
    Get-ItemProperty $Path | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |  Where-Object {$_.InstallDate -lt $StartDate} | Export-Csv C:\InstalledSoftware.csv

    This is only an idea.

    Saturday, January 12, 2019 9:51 PM
  • Try something like this:

    $Path = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
    $Today = (Get-Date)
    $StartDate = $today.AddDays(-14)
    Get-ItemProperty $Path | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |  Where-Object {$_.InstallDate -lt $StartDate} | Export-Csv C:\InstalledSoftware.csv

    This is only an idea.


    Won't work.  Date won't work. TO match a date you must have a date object and you only have a string.  You cannot match a string with anything using -lt.  The operator is also wrong.  We need to be "greater than" the earliest date.

    \_(ツ)_/

    Saturday, January 12, 2019 10:41 PM
  • With WMI we can match strings if we match the correct type of string:

    Get-WmiObject Win32_product -Filter 'InstallDate > "20181130"'

    This works because the string is in the correct decadal format with most significant numbers first.   The comparison works as expected.

    OR …

    $StartDate = $today.AddDays(-14).ToString('yyyyMMdd')
    Get-ItemProperty $Path |
        Where-Object { $_.InstallDate -gt $StartDate } |
        Select-Object DisplayName, DisplayVersion, Publisher, InstallDate 

    Fortunately there are modules and scripts in the Gallery that do this locally and remotely.


    \_(ツ)_/

    Saturday, January 12, 2019 10:52 PM
  • Someone have already done a powershell script that you need. You just need to filter out the date.

    Check out this link: 

    https://techibee.com/powershell/powershell-script-to-query-softwares-installed-on-remote-computer/1389


    • Edited by RATG Sunday, January 13, 2019 1:54 PM
    • Proposed as answer by ComputerScott Thursday, January 24, 2019 9:58 PM
    Sunday, January 13, 2019 1:52 PM