Search code examples
powershellwindows-server-2003hotfix

Powershell to get Hotfix information


I'm looking to get Windows Hotfix information from 2003 servers. For this im using the following PowerShell script as Get-Hotfix does not return all the installed dates. What I would like to do is get only updates applied after a certain date. How could this be done?

    $computername = "Compter01"
    $HotFix = Get-WmiObject win32_ntlogevent -filter "(logfile='system') AND (sourcename='ntservicepack')" -cn $computername |
    select @{name="ServerName"; e={$_.__Server}},Message,@{label="Date Installed"; expression={$_.ConverttoDateTime($_.TimeWritten)}}

Solution

  • Try this:

    $date = [datetime]'1/1/2013'
    $computername = "Compter01"
    $HotFix = Get-WmiObject win32_ntlogevent -filter "(logfile='system') AND (sourcename='ntservicepack')" -cn $computername | 
        Where {$_.ConvertToDateTime($_.TimeWritten) -gt $date} | 
        Select @{name="ServerName"; e={$_.__Server}},Message,@{label="Date Installed"; expression={$_.ConverttoDateTime($_.TimeWritten)}}
    

    There may be a way to filter out dates using the WMI filter query but that's not my area of expertise.