Check if patch exists and report to Excel

Using Powershell and Microsoft Excel

Here is a great way to use powershell to check if a particular patch has been applied to a list of machines. The script is modular so you can replace the KB numbers when needed.

checkifpatchexists.ps
source code
$erroractionpreference = "Continue"

$a = New-Object -comobject Excel.Application
$a.visible = $True 

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "PatchStatus"
$c.Cells.Item(1,3) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

Foreach ($strComputer in get-content C:\MachineList.Txt)
{
$c.Cells.Item($intRow,1) = $strComputer

$PatchStatus = Get-WMIObject Win32_QuickFixEngineering -computer 
$strcomputer | where {$_.HotFixID -eq "KB925902"}
If($PatchStatus -eq $Null)
{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 3
$c.Cells.Item($intRow,2) = "NO"
}
Else
{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 4
$c.Cells.Item($intRow,2) = "YES"
}
$c.Cells.Item($intRow,3) = Get-Date
$intRow = $intRow + 1
}

$d.EntireColumn.AutoFit()
cls
source code