PowerShell – Return List of Windows Updates from Microsoft

email me

This will return available Windows Updates

$WindowsUpdates = new-object -com "Microsoft.Update.Searcher"
$historyCount = $WindowsUpdates.GetTotalHistoryCount()
$updates = $WindowsUpdates.QueryHistory(0,$historyCount)
 
$Array =  @()
             
Foreach ($update in $updates)
    {
    $string = $update.title
 
    $Regex = "KB\d*"
    $KB = $string | Select-String -Pattern $regex | Select-Object { $_.Matches }
    $updateQueue = New-Object -TypeName PSobject
    $updateQueue | add-member NoteProperty "HotFixID" -value $KB.' $_.Matches '.Value
    #$updateQueue | add-member NoteProperty "Title" -value $string
    $Array += $updateQueue 
    }
 
$Array | 
Sort-Object HotFixID | 
Format-Table -AutoSize
Write-Host "$($Array.Count) updates found!"

#$Array | Sort-Object HotFixID -unique
#$results = $Array | Sort-Object HotFixID -unique
#$results | Out-File -FilePath C:\POWERSHELL\ReturnUpdates.txt

 

Screenshot