In this post we provide a quick example of how we can use PowerShell to retrieve all Windows updates and patches.
Get-HotFix Not Returning All Installed KBs
The first thought that springs to mind is simply to run
Get-Hotfix
. However this only returns a subset of windows updates supplied by Component Based Servicing.
A more comprehensive way of returning historic windows updates and patches is to use the Microsoft Update Session object like so:
cls
$session = New-Object -ComObject "Microsoft.Update.Session"
$searcher = $Session.CreateUpdateSearcher()
$totalHistoryCount = $Searcher.GetTotalHistoryCount()
$searcher.QueryHistory(0, $totalHistoryCount) | Select-Object -Property @{Name = 'Name'; Expression = {[regex]::match($_.Title,'KB\d{7}').Groups[0].Value}}, Title, Date
If we wanted to search for a specific KB reference we can simply pipe the output into
Where
like so:
cls
$session = New-Object -ComObject "Microsoft.Update.Session"
$searcher = $Session.CreateUpdateSearcher()
$totalHistoryCount = $Searcher.GetTotalHistoryCount()
$searcher.QueryHistory(0, $totalHistoryCount) | Select-Object -Property @{Name = 'Name'; Expression = {[regex]::match($_.Title,'KB\d{7}').Groups[0].Value}}, Title, Date | Where Name -eq "KB2267602"
![Use PowerShell to Retrieve All Windows Updates and Patches](https://www.alkanesolutions.co.uk/wp-content/uploads/2023/12/use-powershell-to-retrieve-all-windows-updates-and-patches-300x169.png)
![Use PowerShell to Retrieve All Windows Updates and Patches](https://www.alkanesolutions.co.uk/wp-content/themes/twentyeleven-child/images/application-packaging-services-blog.png)