In the past I have used this code to list the count of windows patches:
$server = 'ServerName'
$updatesession = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session", $Server))
$updatesearcher = $updatesession.CreateUpdateSearcher()
$searchresult = $updatesearcher.Search("IsInstalled=0")
$PatchCount = $searchresult.Updates.Count
return $PatchCount
However, this code suddenly stopped working for some servers. This could be an artifact of recent windows updates. A similar script (which is also failing) is here.
This is the exception I get:
Exception from HRESULT: 0x8024401C At line:5 char:1 + $searchresult = $updatesearcher.Search("IsInstalled=0") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Appreciate any help in fixing this code (or if there's a better alternative, that would work too.)
It looks like the 0x8024401C
code means that the Windows Update service could not be contacted.
User contributions licensed under CC BY-SA 3.0