-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinstall_kb.ps1.erb
25 lines (24 loc) · 1.2 KB
/
install_kb.ps1.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ProgressPreference = 'SilentlyContinue'
$LibDir = "$env:ProgramData\PuppetLabs\puppet\cache\lib\patching_as_code"
$LibDir += "\errorcodes.txt"
$all_error_codes = Get-Content -raw -Path $LibDir | ConvertFrom-StringData
[void](Install-WindowsUpdate -KBArticleID "<%= @kb %>" -AcceptAll -IgnoreReboot)
Start-Sleep 5
$update = Get-WUHistory -Last 500 | ? KB -eq <%= @kb %> | Sort-Object Date -Descending | Select-Object -First 1
switch -regex ($update.Result) {
'Succeeded' { Set-Content "C:\ProgramData\InstalledUpdates\<%= @kb %>.flg" "Installed" }
'SucceededWithErrors|InProgress' {
$HResult = [Convert]::ToString($update.HResult, 16)
$Message = $all_error_codes["0x$HResult"]
Write-Output "Update <%= @kb %> was installed but reported (likely reboot needed): $Message"
Set-Content "C:\ProgramData\InstalledUpdates\<%= @kb %>.flg" "Installed"
Exit 0
}
'Failed' {
$HResult = [Convert]::ToString($update.HResult, 16)
$Message = $all_error_codes["0x$HResult"]
Write-Output "Update <%= @kb %> failed to install, reporting: $Message"
Exit 2
}
default { Write-Output "Update <%= @kb %> is not provided by the update server!"; Exit 0 }
}