Skip to content

Instantly share code, notes, and snippets.

@DanielRuskin1
Forked from jacobludriks/wsus-update.ps1
Last active April 24, 2016 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielRuskin1/487e4bdea5de5928f133b6c49e2e920f to your computer and use it in GitHub Desktop.
Save DanielRuskin1/487e4bdea5de5928f133b6c49e2e920f to your computer and use it in GitHub Desktop.
wsus-update
Function WSUSUpdate {
$Criteria = "IsInstalled=0 and BrowseOnly=0"
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
try {
$SearchResult = $Searcher.Search($Criteria).Updates
if ($SearchResult.Count -eq 0) {
Write-Output "There are no applicable updates."
exit
}
else {
$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $SearchResult
$Downloader.Download()
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $SearchResult
$Result = $Installer.Install()
}
}
catch {
Write-Output "There are no applicable updates."
}
}
WSUSUpdate
If ($Result.rebootRequired) { Restart-Computer }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment