Skip to content

Instantly share code, notes, and snippets.

@firefalc0n
Created October 7, 2017 08:55
Show Gist options
  • Save firefalc0n/68dd0071cd828a262b78c6bc7240741e to your computer and use it in GitHub Desktop.
Save firefalc0n/68dd0071cd828a262b78c6bc7240741e to your computer and use it in GitHub Desktop.
# Gives a list of all Microsoft Updates sorted by KB number/HotfixID
# By Tom Arbuthnot. Lyncdup.com
$wu = new-object -com “Microsoft.Update.Searcher”
$totalupdates = $wu.GetTotalHistoryCount()
$all = $wu.QueryHistory(0,$totalupdates)
# Define a new array to gather output
$OutputCollection= @()
Foreach ($update in $all)
{
$string = $update.title
$Regex = “KB\d*”
$KB = $string | Select-String -Pattern $regex | Select-Object { $_.Matches }
$output = New-Object -TypeName PSobject
$output | add-member NoteProperty “HotFixID” -value $KB.‘ $_.Matches ‘.Value
$output | add-member NoteProperty “Title” -value $string
$OutputCollection += $output
}
# Oupput the collection sorted and formatted:
$OutputCollection | Sort-Object HotFixID | Format-Table -AutoSize
Write-Host “$($OutputCollection.Count) Updates Found”
# If you want to output the collection as an object, just remove the two lines above and replace them with “$OutputCollection”
# credit/thanks:
# http://blogs.technet.com/b/tmintner/archive/2006/07/07/440729.aspx
# http://www.gfi.com/blog/windows-powershell-extracting-strings-using-regular-expressions/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment