Get latest installed update with PowerShell

Assuming you have an array of computers (be it from LDAP or otherwise) you can quickly enumerate them using the WMI Win32_QuickFixEngineering class to check the most recently installed HotFix.

Whilst WSUS will likely provide much of this functionality for those using it, this may still prove useful to some.

$compList = "LONDON", "BRISBANE"
$ErrorActionPreference = "Stop";
$tblResults = New-Object System.Data.DataTable "Results"

$colA = New-Object System.Data.DataColumn ComputerName, ([string])
$colB = New-Object System.Data.DataColumn LastHotFixID, ([string])
$colC = New-Object System.Data.DataColumn LastUpdated, ([string])

$tblResults.Columns.Add( $colA )
$tblResults.Columns.Add( $colB )
$tblResults.Columns.Add( $colC )

foreach ($computer in $compList)
{
	try
	{
		$latestUpdate = Get-WMIObject -Class Win32_QuickFixEngineering -ComputerName $computer -Filter "HotFixID != 'File 1'"| ? {$_.InstalledON} |sort InstalledOn | select -last 1
		$newRow = $tblResults.newrow()
		$newRow.ComputerName = $computer
		$newRow.LastHotFixID = $latestUpdate.HotFixID
		$newRow.LastUpdated = "{0:dd/MM/yyyy}" -f [DateTime] $latestUpdate.InstalledOn.Date
		$tblResults.Rows.Add( $newRow )
	}
	catch
	{
		$computer
	}
}
$tblResults

Save the above to a file with the “ps1” extension and adjust the $compList variable to contain the computers you wish to scan.

The only oddity in this I’ve discovered is if the updates are slipstreamed into the installation WIM they do not have an install date associated with them.

Published by

Dave Hope

Dave is a Principal Software Analyst for a UK based retirement developer, in his spare time he enjoys digital photography and rock climbing.

One thought on “Get latest installed update with PowerShell”

Leave a Reply

Your email address will not be published. Required fields are marked *