PowerShell – Excel Report for a Single Hotfix

email me

# KB to check 
$KB = "KB3176935"

# List of computers to check for KB
$computerList = 'C:\reports\computers.txt'

$setErrorAction = "SilentlyContinue"

# Application setup
$application = New-Object -comobject Excel.Application 
$application.visible = $True
$workbook = $application.Workbooks.Add() 
$addWorksheetItem = $workbook.Worksheets.Item(1)
$initialRow = 2

# Header Properties
$addWorksheetItem.Cells.Item(1,1) = "COMPUTER" 
$addWorksheetItem.Cells.Item(1,2) = "STATUS" 
$headerProperty = $addWorksheetItem.UsedRange
$headerProperty.Interior.ColorIndex = 0
$headerProperty.Font.ColorIndex = 0 
$headerProperty.Font.Bold = $True

# Cycle through computer list
Foreach ($computer in get-content $computerList) 
{     
    $addWorksheetItem.Cells.Item($initialRow,1) = $computer

    $PatchStatus = Get-WMIObject Win32_QuickFixEngineering -computer $computer | where {$_.HotFixID -eq $KB} 
        If($PatchStatus -eq $Null) 
            {   # KB not found
                $addWorksheetItem.Cells.Item($initialRow,2).Interior.ColorIndex = 0 
                $addWorksheetItem.Cells.Item($initialRow,2) = "FALSE" 
            } 
        Else 
            {   # KB found
                $addWorksheetItem.Cells.Item($initialRow,2).Interior.ColorIndex = 0 
                $addWorksheetItem.Cells.Item($initialRow,2) = "TRUE" 
            } 
    
            $initialRow = $initialRow + 1 
            }

    # Resize columns to fix
    $headerProperty.EntireColumn.AutoFit() 

 
 
Screenshot