Friday, 4 November 2016

Powershell for finding hotfixes

One liner:

$Session = New-Object -ComObject Microsoft.Update.Session; $Searcher = $Session.CreateUpdateSearcher(); $HistoryCount = $Searcher.GetTotalHistoryCount();$Searcher.QueryHistory(0,$HistoryCount) | Sort-Object -Property Date -Descending | Select Title, Date | Export-Csv -Path c:\temp\hotfixlist.csv

More full version:


$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 | Out-File c:\temp\output.txt

Further reading
https://github.com/tomarbuthnot/Get-MicrosoftUpdate

No comments:

Post a Comment

Android mediaserver process killing battery life

If this happens to you, then do the following Force stop on Settings, Applications, All, Media Storage. Clear Cache and Clear Data, fo...