Iris Classon
Iris Classon - In Love with Code

Using PowerShell to summarize pending Windows Updates as well as installed updates

Merry Christmas! I hope you’ve had a lovely Christmas holiday, with food, love and fun! We spent a laid back Christmas with my best friend Jonas and his fiance, and with then two weeks old Loke Tiberiu. We had planned to travel to Norway, but with my due date being right before Christmas we planned the celebration in Sweden instead- just the five of us to avoid getting Loke sick.

A few months back I was writing about Windows Updates as I came across some problems while manually running the updates on our machines at work. I wrote a tiny script to check for pending updates (excluding anything related to Silverlight updates) that we can run on all our machines to generate a quick report. It’s a temporary solution until we tweak our monitoring and management tools.

Anyways, here is the script:

 
$msUpdateSession = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session",$env:COMPUTERNAME))
$updates = $msUpdateSession.CreateUpdateSearcher().Search("IsInstalled=0").Updates

$silverLightInstalled = Get-WindowsFeature | where { $_.Name.ToLower() -like 'silverlight' }

$pendingUpdates = [System.Collections.ArrayList]@()

$updates | % {

$title = $_.Title

if ($_.Title.ToLower().Contains("silverlight")){
   if($silverLightInstalled){
       $pendingUpdates.Add($title)}
}

else{
       $pendingUpdates.Add($title)
   }
}

$updatesCount = $pendingUpdates.Count

if($updatesCount -gt 0){
   Write-Host "***** $updatesCount updates pending for Iris Awesome COmputer*****" -BackgroundColor Black -ForegroundColor Yellow
   $pendingUpdates | % { Write-Host $_}
}

else{
   Write-Host "***** No pending updates for $env:COMPUTERNAME*****" -BackgroundColor Black -ForegroundColor Green
}

Result (updates are now installed ;) )
windows updates PoSh

Comments

Leave a comment below, or by email.


Last modified on 2018-12-27

comments powered by Disqus