kbupdate
kbupdate copied to clipboard
New command to force install missing patches?
Would be paired with https://github.com/potatoqualitee/kbupdate/issues/59
# get available updates for query
$UpdateSession = New-Object -com Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$SearchResult = $UpdateSearcher.Search("Type!='Driver' and IsHidden=0 and IsInstalled=0")
# create a collection
$updateCollection=New-Object -com Microsoft.Update.UpdateColl
For($i=0; $i -lt $searchResult.Updates.Count; $i++){
$update=$searchResult.Updates.Item($i)
$update.EulaAccepted
if(-not $update.EulaAccepted){
Write-Host "Accepting EULA for $update" -ForegroundColor green
$Update.AcceptEula()}
[void]$updateCollection.Add($Update)
}
#display all updates selected
$updateCollection |
ForEach-Object {}
$updateCollection|%{Write-Host ("{0,-10}{1,-30}" -f $($_.KBArticleIDs),$_.Title) -fore green
}
# call downloader with collection
$downloader=$UpdateSession.CreateUpdateDownloader()
$downloader.Updates=$updateCollection
$Downloader.Download()
# call installer with same collection.
$installer = $UpdateSession.CreateUpdateInstaller()
$installer.ForceQuiet=$true
$installer.Updates=$updateCollection
$result=$Installer.Install()
if($result.ResultCode -eq 2){
Write-host " Installation Succeeded" -foregroundcolor green
Write-Host "Reboot required $($result.RebootRequired)" -Fore green
}else{
Write-host " INSTALLATION FAILED, check event log for details" -foregroundcolor red
}
https://social.technet.microsoft.com/Forums/en-US/5ac70b68-d935-42b7-868e-acd082b2e4b8/powershell-script-improvement-needed-for-windows-updates?forum=ITCG
ayyy nice, thanks 🥔
how to make this work in offline envs without a WSUS server tho? maybe that cab?
ref: #132
https://github.com/rgl/packer-plugin-windows-update/blob/master/update/windows-update.ps1
done in recent versions