Skip to content

Instantly share code, notes, and snippets.

@pgfitzgerald
Last active May 21, 2017 17:37
Show Gist options
  • Save pgfitzgerald/60ca500ee30a976be645b16e0e1734f4 to your computer and use it in GitHub Desktop.
Save pgfitzgerald/60ca500ee30a976be645b16e0e1734f4 to your computer and use it in GitHub Desktop.
# Based on a script from Mike F. Robbins | https://twitter.com/mikefrobbins
# http://mikefrobbins.com/2017/05/18/use-powershell-to-determine-if-specific-windows-updates-are-installed-on-remote-servers/
# Customized by Paul G. Fitzgerald | https://twitter.com/pgfitzgerald
$Timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$Computers = Get-ADComputer -Filter *
# Adjust ThrottleLimit as needed
Invoke-Command -ComputerName ($Computers | Select-Object -ExpandProperty Name) -ThrottleLimit 32 -ScriptBlock {
$Patches = 'KB4012598', # Windows XP, Windows Vista, Windows 8, Windows Server 2003
'KB4018466', # Windows Server 2008
'KB4012212', 'KB4012215', 'KB4012218', 'KB4015549', 'KB4015552', 'KB4019264', # Windows 7, Windows Server 2008 R2
'KB4012214', 'KB4012217', 'KB4012220', 'KB4015551', 'KB4015554', 'KB4019216', # Windows Server 2012
'KB4012213', 'KB4012216', 'KB4012219', 'KB4015550', 'KB4015553', 'KB4019215', # Windows 8.1, Windows Server 2012 R2
'KB4012606', 'KB4016637', 'KB4015221', 'KB4019474', # Windows 10 1507, Windows 10 LTSB 2015
'KB4013198', 'KB4016636', 'KB4015219', 'KB4019473', # Windows 10 1511
'KB4013429', 'KB4016635', 'KB4015217', 'KB4019472', # Windows 10 1607, Windows 10 LTSB 2016, Windows Server 2016
'KB4016251', 'KB4015583', 'KB4016240', 'KB4016871' # Windows 10 1703
Write-Host "Checking $env:COMPUTERNAME"
Get-HotFix -Id $Patches
} -ErrorAction SilentlyContinue -ErrorVariable Problems | Select-Object -Property @{Name="ComputerName";Expression={$_.PSComputerName}},HotFixID,InstalledOn | Export-Csv -Path "$Timestamp Patched Computers.csv" -Encoding UTF8 -NoTypeInformation
$UnpatchedComputers = @()
$ComputersWithErrors = @()
foreach ($Problem in $Problems) {
if ($Problem.OriginInfo.PSComputerName) {
Write-Warning -Message "Patch not found on $($Problem.OriginInfo.PSComputerName)"
$Computer = New-Object -TypeName PSObject
$Computer | Add-Member -NotePropertyName ComputerName -NotePropertyValue $Problem.OriginInfo.PSComputerName
$UnpatchedComputers += $Computer
Remove-Variable -Name Computer
} elseif ($Problem.TargetObject) {
Write-Warning -Message "Unable to connect to $($Problem.TargetObject)"
$Computer = New-Object -TypeName PSObject
$Computer | Add-Member -NotePropertyName ComputerName -NotePropertyValue $Problem.TargetObject
$ComputersWithErrors += $Computer
Remove-Variable -Name Computer
}
}
$UnpatchedComputers | Export-Csv -Path "$Timestamp Unpatched Computers.csv" -Encoding UTF8 -NoTypeInformation
$ComputersWithErrors | Export-Csv -Path "$Timestamp Computers With Errors.csv" -Encoding UTF8 -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment