Finding Installed Updates (and searching for missing) (Part 2)

by Aug 3, 2017

When PowerShell asks Windows for updates via the Microsoft.Update.Session object, some information seems to be unreadable. The code below dumps information about installed updates. The property “KBArticleIDs”, however, just displays “ComObject”.

#requires -Version 2.0

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$updates = $Searcher.Search("IsInstalled=1").Updates 

$updates |
  Select-Object -Property Title, LastDeploy*, Desc*, MaxDownload*, KBArticleIDs |
  Out-GridView

To work around this, use a calculated property where you pipe the unreadable COM Object to Out-String. This way, PowerShell’s internal logic uses its magic to decipher the COM Object content:

#requires -Version 2.0

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$updates = $Searcher.Search("IsInstalled=1").Updates 

$KBArticleIDs = @{
    Name = 'KBArticleIDs'
    Expression = { ($_.KBArticleIDs | Out-String).Trim() }
}

$updates |
  Select-Object -Property Title, LastDeploy*, Desc*, MaxDownload*, $KBArticleIDs |
  Out-GridView

Twitter This Tip! ReTweet this Tip!