PoshCode Logo PowerShell Code Repository

Compare-InstalledHotfix by Andy Schneider 7 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1296"></script>download | new post

Takes two servers and provides the delta of installed hotfixes between them

  1. Function Compare-InstalledHotfix {
  2. param (
  3. [parameter(Mandatory=$true,Position=0)]
  4. $server1,
  5.  
  6. [parameter(Mandatory=$true,Position=1)]
  7. $server2,
  8.  
  9. [parameter(Mandatory=$true,Position=3)]
  10. [Management.Automation.PSCredential]
  11. $credential
  12. )
  13.  
  14. $server1HotFix = get-hotfix -computer $server1 -Credential $credential | select HotfixId
  15. $server2HotFix = get-hotfix -computer $server2 -Credential $credential | select HotfixId
  16.  
  17. $comparedHotfixes = compare-object $server2HotFix $server1HotFix -IncludeEqual
  18.  
  19. $result = @();
  20.  
  21. foreach ($c in $comparedHotfixes) {
  22.     $kbinfo = "" | select KB,$server1,$server2
  23.     $kbinfo.KB = $c.InputObject.HotfixId
  24.     switch ($c.SideIndicator)
  25.     {
  26.     "==" {
  27.             write-host -ForegroundColor Green "Both servers have $($c.InputObject.HotfixId)"
  28.             $kbinfo.($server1) = $true
  29.             $kbinfo.($server2) = $true
  30.             $result += $kbinfo
  31.          }
  32.          
  33.     "=>" {
  34.             write-host -ForegroundColor Yellow "$server1 has $($c.InputObject.HotfixId) but $server2 doesn't"
  35.             $kbinfo.($server1) = $true
  36.             $kbinfo.($server2) = $false
  37.             $result += $kbinfo
  38.           }
  39.          
  40.     "<="  {
  41.             write-host -ForegroundColor Magenta "$server2 has $($c.InputObject.HotfixId) but $server1 doesn't"
  42.             $kbinfo.($server1) = $false
  43.             $kbinfo.($server2) = $true
  44.             $result += $kbinfo
  45.           }
  46.     } # End Switch
  47.   } # End foreach
  48.    $result
  49.  } # End Function

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me