Lerch Web Wiki

Random, erratic, no responsibility is taken for the correctness of this information

User Tools

Site Tools


Hot(fix) or not(fix)?

Today one of my customers asked me how they can easily compare installed hofixes on Windows Servers.

Powershell to the rescue! To get the installed hotfixes from a server (local or remote) we can use the Get-HotFix cmdlet in Powershell. So all we need to do is compare the output. Depending on the number of hotfixes this can be a pain in the neck if you try to do it manually. And the more servers you need to compare the more pain…

With Powershell hashtables and a little scripting the comparison is easily automated, so you can see which hotfixes are installed on your servers and if they are all on the same hotfix level.

Save the following script as Compare-HotFix.ps1 and give it a try:

    [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
Begin {$htHF = @{}}
Process {
    $ServerList | foreach-object {
        Write-Verbose "Getting hotfixes from server $_"
        $hf1 = Get-HotFix -ComputerName $_ | Select-Object -Property HotFixID,CSName
        foreach ($hf in $hf1){
            try {
                if($htHF.Item($hf.HotFixID) -notcontains $hf.CSName){
                $htHF.Item($hf.HotFixID) += $hf.CSName
End {$htHF | Sort-Object -Property Name}

The script takes one or more server names as strings or you can pipe the server names to it.

Use it like this:

.\compare-hotfix.ps1 server1,server2,server3

or this:

$Servers = “server1″,”server2″,”server3″,”serverN”
$Server | .\compare-hotfix.ps1

or if you have a list of server names in a text file you do something like this:

get-content Serverlist.txt | .\compare-hotfix.ps1

Have fun playing around with it!

powershell/plattform/compare-hotfix.txt · Last modified: 2017/02/20 10:41 (external edit)