PowerShell - Get HotFix (KB) Report
- Jon Boyette
- Jan 12, 2022
- 1 min read
Save as GetHotFixReport.ps1, or as desired, gets HostName, If Reachable, Last Boot Time, Last 5 Hot Fixes or KB's installed (Configurable), Last patch installed on date, Installed by, Description and the Current auto stopped services of servers populated in c:\temp\servers.txt
$comp= gc "c:\temp\servers.txt"
$infoObject=@()
$results=@()
foreach($co in $comp)
{
$co
$css = @"
<style>
h1, h5, th { text-align: center; font-family: Segoe UI; }
table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; }
td { font-size: 11px; padding: 5px 20px; color: #000; }
tr { background: #b8d1f3; }
tr:nth-child(even) { background: #dae5f4; }
tr:nth-child(odd) { background: #b8d1f3; }
</style>
"@
$infoObject = New-Object PSObject
$p=Test-Connection -ComputerName $co -BufferSize 16 -Count 1 -Quiet
$p
$hotfix= Get-WmiObject -Class Win32_quickfixengineering -ComputerName $co |select Hotfixid -Last 5
$h=($hotfix|select @{Name="fixes" ;expression={$hotfix.hotfixid -join ","}} -Last 1).fixes
$h
$description = Get-WmiObject -Class Win32_quickfixengineering -ComputerName $co|select -ExpandProperty Description -last 1
$description
$installedby = Get-WmiObject -Class Win32_quickfixengineering -ComputerName $co|select -ExpandProperty Installedby -last 1
$installedby
$installedon = Get-WmiObject -Class Win32_quickfixengineering -ComputerName $co|select -ExpandProperty Installedon -last 1
$installedon
$Boottime = Get-WmiObject -Class Win32_operatingsystem -ComputerName $co |select -ExpandProperty LastBootUpTime
$b = ($Boottime|select @{Name="LastBootUpTime" ;EXPRESSION={$co.ConverttoDateTime}}.Lastbootuptime)
$b
$service = Get-WmiObject -ClassName Win32_Service -Filter "StartMode='Auto' AND State<>'Running'" -computername $co
$r = ($service|select @{Name="Service" ;expression={$service.name -join ","}} -Last 1).service
$r
$infoObject|Add-Member -MemberType NoteProperty -Name "Hostname" -value $co
$infoObject|Add-Member -MemberType NoteProperty -Name "Reachable" -value $p
$infoObject|Add-Member -MemberType NoteProperty -Name "Last Boot Up Time" -value $b
$infoObject|Add-Member -MemberType NoteProperty -Name "Hotfix ID" -Value $h
$infoObject|Add-Member -MemberType NoteProperty -Name "Last Patch Installed On" -Value $installedon
$infoObject|Add-Member -MemberType NoteProperty -Name "Installed By" -Value $installedby
$infoObject|Add-Member -MemberType NoteProperty -Name "Description" -Value $description
$infoObject|Add-Member -MemberType NoteProperty -Name "Current Auto Stopped services" -Value $r
$results+=$infoObject
}
$results | Export-Csv c:\temp\ServerHotfixReport.csv
Comments