SHOW:
|
|
- or go back to the newest paste.
| 1 | <# | |
| 2 | .Synopsis | |
| 3 | Gathers hotfixes for all computers in a list then returns a list of hotfixes that are only installed on some of the nodes. | |
| 4 | .DESCRIPTION | |
| 5 | Given a list of computers, this cmdlet verifies each computer is reachable and then gathers a list of hotfixes installed on each computer. It will then either display a table of all hotfixes | |
| 6 | that are only installed on a subset of the computers specified or, if the DisplayAllHotfixes switch is specified, a table of all hotfixes installed on all computers. The first column | |
| 7 | is the HotfixID and each other column (property) is the computer name; if the hotfix is installed on that computer it's marked "True", if not it's marked "False". | |
| 8 | .EXAMPLE | |
| 9 | $computerlist = @("ServerA", "ServerB", "ServerC")
| |
| 10 | Get-HotfixDiscrepancyReport -ComputerList $serverlist | |
| 11 | ||
| 12 | Generates a hotfix report for three servers. | |
| 13 | .EXAMPLE | |
| 14 | Get-HotfixDiscrepancyReport -Computerlist ComputerA, ComputerB, ComputerC -DisplayAllHotfixes | Export-CSV .\hfreport.csv | |
| 15 | ||
| 16 | Lists all hotfixes and whether or not they're installed for three computers and exports the list to a CSV file. | |
| 17 | #> | |
| 18 | function Get-HotfixDiscrepancyReport | |
| 19 | {
| |
| 20 | [CmdletBinding()] | |
| 21 | [OutputType([PSObject[]])] | |
| 22 | Param | |
| 23 | ( | |
| 24 | # A list of computers - can be an array variable or a comma delimited list of computers | |
| 25 | [Parameter(Mandatory=$true, | |
| 26 | ValueFromPipeline=$true, | |
| 27 | Position=0)] | |
| 28 | [Array]$ComputerList, | |
| 29 | ||
| 30 | # If you want to display all hotfixes instead of just hotfixes that aren't installed on every computer | |
| 31 | [Switch]$DisplayAllHotfixes | |
| 32 | ) | |
| 33 | ||
| 34 | Process | |
| 35 | {
| |
| 36 | - | Write-Verbose ("" + (TS) + "Verifying computer list")
|
| 36 | + | Write-Verbose ("Verifying computer list")
|
| 37 | $VerifiedComputers = @() | |
| 38 | foreach ($computer in $ComputerList) | |
| 39 | {
| |
| 40 | if(Test-Connection $computer -Count 1 -ErrorAction SilentlyContinue) | |
| 41 | {
| |
| 42 | $VerifiedComputers += $computer | |
| 43 | } | |
| 44 | else | |
| 45 | {
| |
| 46 | - | Write-Verbose ("" + (TS) + "$computer failed ping; skipping")
|
| 46 | + | Write-Verbose ("$computer failed ping; skipping")
|
| 47 | } | |
| 48 | } | |
| 49 | If ($VerifiedComputers.Count -lt 2) | |
| 50 | {
| |
| 51 | Write-Error -Message "Not enough computers to generate a report. If your initial list had more than one computer, enable verbose mode to see which computers are failing." | |
| 52 | return | |
| 53 | } | |
| 54 | [hashtable]$InstalledHotfixes = @{}
| |
| 55 | - | Write-Verbose ("" + (TS) + "Getting hotfixes for " + $VerifiedComputers[0])
|
| 55 | + | Write-Verbose ("Getting hotfixes for " + $VerifiedComputers[0])
|
| 56 | Get-WmiObject Win32_QuickFixEngineering -Computername $VerifiedComputers[0] | % {
| |
| 57 | $InstalledHotfixes.Add($_.HotfixId, @($VerifiedComputers[0])) | |
| 58 | } | |
| 59 | for ($i = 1; $i -lt $VerifiedComputers.Count; $i++) | |
| 60 | {
| |
| 61 | - | Write-Verbose ("" + (TS) + "Getting hotfixes for " + $VerifiedComputers[$i])
|
| 61 | + | Write-Verbose ("Getting hotfixes for " + $VerifiedComputers[$i])
|
| 62 | Get-WmiObject Win32_QuickFixEngineering -ComputerName $VerifiedComputers[$i] | % {
| |
| 63 | ||
| 64 | if ($InstalledHotfixes.ContainsKey($_.HotfixID)) | |
| 65 | {
| |
| 66 | $InstalledHotfixes.Set_Item($_.HotfixID,($InstalledHotfixes.Get_Item($_.HotfixId) + $VerifiedComputers[$i])) | |
| 67 | } | |
| 68 | else | |
| 69 | {
| |
| 70 | $InstalledHotfixes.Add($_.HotfixId, @($VerifiedComputers[$i])) | |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | if (!$DisplayAllHotfixes) | |
| 75 | {
| |
| 76 | - | Write-Verbose ("" + (TS) + "Filtering list to only hotfixes not on all nodes")
|
| 76 | + | Write-Verbose ("Filtering list to only hotfixes not on all nodes")
|
| 77 | $NewHfList = @{}
| |
| 78 | $InstalledHotfixes.GetEnumerator() | % {if ($_.Value.Count -lt $VerifiedComputers.count) {$NewHfList.Add($_.Key,$_.Value)}}
| |
| 79 | } | |
| 80 | else | |
| 81 | {
| |
| 82 | $NewHfList = $InstalledHotfixes | |
| 83 | } | |
| 84 | $hfdiscrepancylist = @() | |
| 85 | - | Write-Verbose ("" + (TS) + "Creating hotfix list")
|
| 85 | + | Write-Verbose ("Creating hotfix list")
|
| 86 | $NewHfList.GetEnumerator() | % {
| |
| 87 | $hfditem = "" | Select HotfixID | |
| 88 | $hfditem.HotfixID = $_.Key | |
| 89 | foreach ($computer in $VerifiedComputers) | |
| 90 | {
| |
| 91 | $hfditem | Add-Member -NotePropertyName $computer -NotePropertyValue ([boolean]($_.Value -contains $computer)) | |
| 92 | } | |
| 93 | $hfdiscrepancylist += $hfditem | |
| 94 | } | |
| 95 | return $hfdiscrepancylist | Sort-Object HotfixID | |
| 96 | } | |
| 97 | } |