Skip to content

Instantly share code, notes, and snippets.

@Grimthorr
Created November 9, 2015 16:03
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save Grimthorr/44727ea8cf5d3df11cf7 to your computer and use it in GitHub Desktop.
Save Grimthorr/44727ea8cf5d3df11cf7 to your computer and use it in GitHub Desktop.
PowerShell script to list the pending/missing Windows updates.
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates | Select-Object Title
@photonn
Copy link

photonn commented Jan 23, 2018

Perfect script. Just what I was looking for. Thanks!

@royashbrook
Copy link

Ditto! Thanks for this!

@durgaprasad9
Copy link

Hi, When I try to run below one why its not working, please help

I need only .NET available updates

$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates | Where-Object {$_.Title -contains '.NET'} | Select-Object Title

@J0rtIT
Copy link

J0rtIT commented Aug 17, 2018

@durgaprasad9 try to use -like and stars, instead:

$Updates | where{ $_.title -like ".NET"} | select -ExpandProperty Title

@SJayasimha
Copy link

Hi, how to get "Security Updates"only with Title

@Cloudmersive
Copy link

This is great! It seems to show available third party device updates though, e.g. HP printer driver updates. Is there a way to restrict to Windows Updates only?

@AhmedBoSS9001
Copy link

Thank You

@DeRailling
Copy link

I am not a specialist on PS but I love the flexibility of this scripting tool. I've been researching on a similar script that I can modify slightly and provide the same end result for a list of servers we support. That list can be in a simple text file. How could I modify the above script to reflect that?

TIA

Gino

@jav-qwt
Copy link

jav-qwt commented Jun 2, 2021

Thanks Philip !!

@Maheshwaran-S
Copy link

Great this script really helps.

@pratyakshm
Copy link

Hello
This script shows optional updates as well
Is there any way to exclude optional updates?
I tried using $Updates = @($UpdateSearcher.Search("IsMandatory=0").Updates) but it throws OperationStopped: 0x80240032 error.
Thanks in advance.

@fliespl
Copy link

fliespl commented Sep 25, 2021

@pratyakshm

You can find it like that:

$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates | Where-Object IsMandatory -eq $true | Select Title, IsMandatory

@aymenjaz
Copy link

Thanks

@pratyakshm
Copy link

Thanks @fliespl! ❤️

@Kein
Copy link

Kein commented Apr 28, 2022

This appears to be actually skipping optional/recommended updates. I have update preview kb5011831 pending in WU on W10LTSC 21H2 19044.1348 but it is not in the list generated by UpdateSearcher. I've tried supplying empty criteria - still the same result. It does ignore the group policy for "skip drivers in WU" which is nice.

@guillerg86
Copy link

If u need to read from a software like Zabbix or just load in some api or application you can use this

https://github.com/guillerg86/zabbix/blob/main/scripts/windows/powershell/wu-get-mandatory-updates.ps1

@mrbaraclough
Copy link

Thanks, this was perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment