So I have been using this for a while, but can’t remember if I shared it, so here it is. I have two functions to get Installed Updated and Pending Updates.
They use winrm, so if it doesn’t work against a remote server you just need to run winrm qc
function Get-InstalledSoftwareUpdates { param($ComputerName=(HOSTNAME), $Credential) $code = { $Session = New-Object -ComObject Microsoft.Update.Session $Searcher = $Session.CreateUpdateSearcher() $HistoryCount = $Searcher.GetTotalHistoryCount() $Searcher.QueryHistory(1,$HistoryCount) } Invoke-Command $code @psboundparameters | Select @{Expression={$ComputerName};Label="Machine"}, Date, Title, Description, ResultCode }
-and-
function Get-PendingSoftwareUpdates { param($ComputerName=(HOSTNAME), $Credential) $code = { $Session = New-Object -ComObject Microsoft.Update.Session $Searcher = $Session.CreateUpdateSearcher() $HistoryCount = $Searcher.GetTotalHistoryCount() $SearchResult = $Searcher.Search("IsInstalled=0 and Type='Software'") For ($X = 0; $X -lt $SearchResult.Updates.Count; $X++){$SearchResult.Updates.Item($X)} } Invoke-Command $code @psboundparameters | Select @{Expression={$ComputerName};Label="Machine"}, Title, Description, IsHidden, IsMandatory }
You can run it against your windows desktop too, just paste in the functions and run them. Prob best to put them in to a variable so:
$installed = Get-InstalledSoftwareUpdates $pending = Get-PendingSoftwareUpdates
I also do some funky html output too, but I will let you play with that ;-)
Enjoy