I recently got the task to inventory all installed updates and hotfixes on a bunch of cluster nodes.
Yes, I could have gone through ‘Add/Remove Programs’ and created a list by hand… right? Are you freakin’ kidding me?
That sounds a heck of a lot like manual labor to me!
Next to that, I could see cases where I would want to check this more often if there area any differences between installed updates/hotfixes between systems…
Over the internet I’ve found a few functions to list installed updates, or use Get-Hotfix to list the installed hotfixes.
What I didn’t find was a script or function to do both… so I wrote one.
… and posted it in the TechNet Script Center. 🙂
As written on the Script Center, you can use the output of this function to compare the installed updates between systems:
1 2 3 4 5 6 7 8 9 10 11 12 |
$AllUpdates = Get-InstalledUpdates -ComputerName 'server1','server2','server3' $server1 = $AllUpdates | Where-Object {$_.PSComputerName -eq 'server1'} | select -ExpandProperty KB -Unique $server2 = $AllUpdates | Where-Object {$_.PSComputerName -eq 'server2'} | select -ExpandProperty KB -Unique $server3 = $AllUpdates | Where-Object {$_.PSComputerName -eq 'server3'} | select -ExpandProperty KB -Unique $server1diff = Compare-Object $AllUpdates $server1 | select -ExpandProperty InputObject $server2diff = Compare-Object $AllUpdates $server2 | select -ExpandProperty InputObject $server3diff = Compare-Object $AllUpdates $server3 | select -ExpandProperty InputObject $server1diff $server2diff $server3diff |
Yeah, I’m a noob. I don’t know how to use a function in powershell.
I’ve grabbed your function code and saved it as get-installedupdates.ps1
but when I try to run it I get:
Get-InstalledUpdates.ps1 -computername ‘xa1001001’ -hotfixes
Get-InstalledUpdates.ps1 : The term ‘Get-InstalledUpdates.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-InstalledUpdates.ps1 -computername ‘xa1001001’ -hotfixes
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-InstalledUpdates.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Hi Jason,
Don’t worry, we all start at the beginning at some point 🙂
You can use a function in the following way: First load it, then call it.
You can load it by opening it in ISE, hit F5 (execute) and then you can use it by calling the name of the function.
In a prompt, you can simply copy-paste the code of the function into a prompt, press ENTER two times and because by then it’s loaded into memory, you can call the function during that PowerShell session.
A script, like you are trying to do, works a little different. This is rather well described in the Learn PowerShell 3 In A Month Of Lunches book, by Don Jones and Jeff Hicks.
In short: Place the actual code (so not the definition of the function (which is “function bla-bla {}” just do be clear)) in the script file, browse to the location of the script in a prompt (i.e. cd c:\users\jeff\script) and execute the script by doing .\myscript.ps1
If you get an error that execution of scripts is disabled on your system, read up on the Execution Policy in PowerShell: http://technet.microsoft.com/library/hh849812.aspx
Jeff.