HotFixInfo.ps1

Generate an Excel spreadsheet listing the servers which have a particular hot fix installed.
By default it will check for the conflicker patch KB958644 but you can change this to any QFE patch.

This is based on the original script by Jesse N. Hamrick at PowerShellPro. This version outputs a line for every server, so you can see the machines which *don't* have the patch, also the script has been adjusted to work with any regional version of MS Excel.

# ======================================================
# HotFixInfo.ps1
#
# Original Author: Jesse N. Hamrick - PowerShellPro.com
# Updated: 27/11/2009 Simon Sheppard - SS64.com
#
# Enumerate hot fixes on all Servers/computers in AD.
# Sends results to an Excel spreadsheet.
# filters for KB958644 (confliker defense)

# Excel must be installed on the computer running the script.

# 
# ======================================================

# Functions

# ======================================================
# Create a spreadsheet and place results.
# Uses WMIObject Win32_QuickFixEngineering to gather hotfix
# info.
# ======================================================
Function loadExcel {
param ([string]$kbaseArticle)
$Excel = New-Object -Com Excel.Application
$ci = [System.Globalization.CultureInfo]'en-us'
# Add a new workbook
$Excelwb = $Excel.workbooks.psbase.gettype().InvokeMember(
"Add",[Reflection.BindingFlags]::InvokeMethod,$null, $Excel.workbooks, $null, $ci)

$Excel.visible = $True

$Sheet = $Excelwb.Worksheets.Item(1)
$Sheet.Cells.Item(1,1).formulalocal = "Computer Name"
$Sheet.Cells.Item(1,2).formulalocal = "Q Article"
$Sheet.Cells.Item(1,3).formulalocal = "Installer"
$Sheet.Cells.Item(1,4).formulalocal = "Install Date"
$Sheet.Cells.Item(1,5).formulalocal = "Description"

$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 19
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

foreach ($StrComputer in $colComputers){
   #Write-Host "processing $StrComputer" 
   $reply = gwmi win32_PingStatus -Filter "Address='$strComputer'"
   if ($reply.statusCode -eq "0"){
      Write-Host "processing $StrComputer to xl" 
      $Sheet.Cells.Item($intRow, 1).formulalocal = $StrComputer
      $SheetcolItems = gwmi Win32_quickFixEngineering -Comp $StrComputer
      foreach ($objItem in $SheetcolItems){
         If ($objItem.HotFixID -eq $kbaseArticle){
            Write-Host "kb found" 
            $Sheet.Cells.Item($intRow, 2).formulalocal = "$kbaseArticle Installed"
            $Sheet.Cells.Item($intRow, 3).formulalocal = $objItem.InstalledBy
            $Sheet.Cells.Item($intRow, 4).formulalocal = $objItem.InstalledOn
            $Sheet.Cells.Item($intRow, 5).formulalocal = $objItem.Description
         }
      }
   $intRow = $intRow + 1
   }
}
$WorkBook.EntireColumn.AutoFit()
clear

#Save workbook
$Excel.workbooks.psbase.gettype().InvokeMember(
"SaveAs",[Reflection.BindingFlags]::InvokeMethod,$null, $Excelwb, "c:\hotfix-$kbaseArticle.xls", $ci) > $null

#Close workbook
#$Excel.workbooks.psbase.gettype().InvokeMember(
#"Close",[Reflection.BindingFlags]::InvokeMethod,$null, $Excelwb, 0, $ci) > $null

#Quit excel
#$Excel.Quit()

}
# END OF Excel function

# ========================================================
# Enumerate computer objects
# ========================================================
Function ListComputers {
$strCategory = "computer"
$strOS = "Windows*Server*"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain

# Uncomment to search all computers
# $objSearcher.Filter = ("(objectCategory=$strCategory)")
# Uncomment to seach only Servers
$objSearcher.Filter = ("(&(objectCategory=$strCategory)(OperatingSystem=$strOS))")

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
{$objComputer = $objResult.Properties; $objComputer.name}
}
#END OF ListComputers FUNCTION

# ========================================================
# Script Body
# ========================================================
$erroractionpreference = "SilentlyContinue"

# Call the ListComputers Function and save results to
# an array called $colComputer. Results are sorted alphabetically.
$colComputers = ListComputers | Sort-Object

# Call the Excel Function, which will use the $colComputers
# array to enumerate hotfix info for each computer in the domain.
loadExcel "KB958644"

#END OF SCRIPT ===============================================

Example

Save the script above as HotFixInfo.ps1 and run it to create the spreadsheet "C:\hotfix-KB958644.xls"

PS C:\> ./HotFixInfo.ps1

To adapt this script to check a different KBase update, just edit the items in Bold above, also if you have Excel 2007 change the file extension to .xlsx

“Ignorance more frequently begets confidence than does knowledge” ~ Charles Darwin

Related:

InstalledApps - List the applications installed
pshinfo - List Ram, Disk Space, Service pack, Uptime


© Copyright SS64.com 1999-2013
Some rights reserved