Skip to content

Instantly share code, notes, and snippets.

@benaadams
Created September 3, 2015 00:49
Show Gist options
  • Select an option

  • Save benaadams/e77a34388a6aaa846909 to your computer and use it in GitHub Desktop.

Select an option

Save benaadams/e77a34388a6aaa846909 to your computer and use it in GitHub Desktop.
Updates Windows
#Define update criteria.
$Criteria = "IsInstalled=0 and Type='Software'"
#Search for relevant updates.
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$SearchResult = $Searcher.Search($Criteria).Updates
#Download updates.
$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $SearchResult
$Downloader.Download()
#Install updates.
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $SearchResult
$Result = $Installer.Install()
#Reboot if required by updates.
If ($Result.rebootRequired) { shutdown.exe /t 0 /r }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment