Skip to content

Instantly share code, notes, and snippets.

@gbraad
Last active September 30, 2022 21:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbraad/463512b065ef1f919e63552138d776bf to your computer and use it in GitHub Desktop.
Save gbraad/463512b065ef1f919e63552138d776bf to your computer and use it in GitHub Desktop.
Query installed and available updates on Windows

Query installed and available updates on Windows

Using PowerShell...

Installed updates

$session = New-Object -ComObject "Microsoft.Update.Session"
$updatesearcher = $session.CreateUpdateSearcher()
$count = $updatesearcher.GetTotalHistoryCount()
$updates = $updatesearcher.QueryHistory(0, $count)

foreach ($update in $updates) {
  $out = New-Object -Type PSObject -Prop @{
    KB = [regex]::match($update.Title,KB(\d+))
    Title = $update.Title
    Description = $update.Description
    Id = $update.UpdateIdentity.UpdateId
    RevisionNumber = $update.UpdateIdentity.RevisionNumber
  }
  Write-Output $out
}

Note: should be improved to consider $update.ResultCode and $update.Operation.

Available updates

$session = New-Object -ComObject "Microsoft.Update.Session"
$updatesearcher = $session.CreateUpdateSearcher()
$searchresult = $updatesearcher.Search("IsInstalled=0")

foreach ($update in $searchresult.Updates) {
  $out = New-Object -Type PSObject -Prop @{
    'Title' =  $update.Title
    'KB' = $($update.KBArticleIDs)
  }
  Write-Output $out
}
@yupsez
Copy link

yupsez commented Sep 17, 2022

Is there a way to list out all updates released for a specific Microsoft Product?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment