It’s nowadays very important to install the latest Windows updates on a monthly basis. If your computer is not recently updated, then it is facing multiple security risks. Cybercriminals are releasing new cybercrime methods every day which can impact your system. As a system engineer, you don’t want to manually check each system by hand. That’s why they invented PowerShell, right?
Windows update commands
There are multiple commands available to check the Windows updates. The most known command is: (Get-Hotfix) With this command you can only return the KB Number and install date. As an engineer, I want to see more information about the installed updates. With the following script, you can find some more information.
1 2 3 4 5 6 7 8 9 10 11 12 |
$Session = New-Object -ComObject "Microsoft.Update.Session" $Searcher = $Session.CreateUpdateSearcher() $historyCount = $Searcher.GetTotalHistoryCount() $InstalledUpdates = $Searcher.QueryHistory(0, $historyCount) | Select-Object Date, @{name="Operation"; expression={switch($_.operation){ 1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}}, @{name="Status"; expression={switch($_.resultcode){ 1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"}; 4 {"Failed"}; 5 {"Aborted"} }}}, @{name="KB"; expression={($_.title | select-string -Pattern 'KB\d*').Matches.Value}}, title | where{$_.title -match "\d{4}-\d{2}"} if(!$InstalledUpdates){ $intall = (Get-HotFix | select hotfixid,installedon |ft -HideTableHeaders | out-string) -creplace '(?m)^\s*\r?\n','' } Else { $install = $InstalledUpdates | where{$_.status -eq "succeeded" -and $_.operation -match "installation"} | % {$_.Title } } $Install |