Show Windows Updates Locally With PowerShell

I wanted to be able to quickly show the Windows Updates on a server. This came about during a discussion about auditing.

Of course, there is no point in re-inventing the wheel so I had a quick Google and  found a couple of posts on from  Hey Scripting Guy blog and one from Tim Minter. Neither quite did what I wanted so I modified them as follows.

We start by creating a Update object and find the total number of updates and setting them to a variable $History which we pass to the QueryHistory Method. This enables us to show all the updates

image

Passing this to Get-Member shows

image

which doesn’t show the KB so I read a bit more and found Tom Arbuthnot’s Blog Post

image

this transforms the ResultCode Property to something meaningful and places the KB in its own column.

I have created a function called Show-WindowsUpdatesLocal It’s Local because doing it for a remote server takes a different approach but I will show that another day.

This means you can call the function and use the results however you like

Show-WindowsUpdatesLocal

image

Show-WindowsUpdatesLocal| Select Date, HotfixID, Result|Format-Table -AutoSize

image

Show-WindowsUpdatesLocal|Where-Object {$_.Result -eq ‘Failed’} |Select Date, HotfixID, Result,Title|Format-Table -AutoSize

image

Output to file Show-WindowsUpdatesLocal|Format-Table -AutoSize|Out-File c:\temp\updates.txt

image

Output to CSV Show-WindowsUpdatesLocal|Export-Csv c:\temp\updates.csv

image

You can get the code here

 

One thought on “Show Windows Updates Locally With PowerShell

  1. Pingback: (SFTW) SQL Server Links 04/10/13 • John Sansom

Please feel free to comment on this post. All comments are moderated first before appearing on the site

This site uses Akismet to reduce spam. Learn how your comment data is processed.