PoshCode Archive  Artifact [1d9492b1d4]

Artifact 1d9492b1d495e2113d45d3a09ae0e88c126dbbb50c9831c3248ecca069bd0913:

  • File Compare-InstalledHotfix.ps1 — part of check-in [ea5f0f061a] at 2018-06-10 12:56:49 on branch trunk — Takes two servers and provides the delta of installed hotfixes between them (user: Andy Schneider size: 1898)

# encoding: ascii
# api: powershell
# title: Compare-InstalledHotfix
# description: Takes two servers and provides the delta of installed hotfixes between them
# version: 0.1
# type: function
# author: Andy Schneider
# license: CC0
# function: Compare-InstalledHotfix
# x-poshcode-id: 1296
# x-archived: 2016-12-24T05:49:28
# x-published: 2009-08-28T07:18:00
#
#
Function Compare-InstalledHotfix {
param (
[parameter(Mandatory=$true,Position=0)]
$server1,

[parameter(Mandatory=$true,Position=1)]
$server2, 

[parameter(Mandatory=$true,Position=3)]
[Management.Automation.PSCredential]
$credential
)

$server1HotFix = get-hotfix -computer $server1 -Credential $credential | select HotfixId
$server2HotFix = get-hotfix -computer $server2 -Credential $credential | select HotfixId

$comparedHotfixes = compare-object $server2HotFix $server1HotFix -IncludeEqual

$result = @();

foreach ($c in $comparedHotfixes) {
    $kbinfo = "" | select KB,$server1,$server2
    $kbinfo.KB = $c.InputObject.HotfixId
    switch ($c.SideIndicator)
    {
    "==" {
            write-host -ForegroundColor Green "Both servers have $($c.InputObject.HotfixId)"
            $kbinfo.($server1) = $true
            $kbinfo.($server2) = $true
            $result += $kbinfo
         }
         
    "=>" {
            write-host -ForegroundColor Yellow "$server1 has $($c.InputObject.HotfixId) but $server2 doesn't"
            $kbinfo.($server1) = $true
            $kbinfo.($server2) = $false
            $result += $kbinfo
          }
          
    "<="  {
            write-host -ForegroundColor Magenta "$server2 has $($c.InputObject.HotfixId) but $server1 doesn't"
            $kbinfo.($server1) = $false
            $kbinfo.($server2) = $true
            $result += $kbinfo
          }
    } # End Switch
  } # End foreach
   $result
 } # End Function