Created
September 3, 2015 00:49
-
-
Save benaadams/e77a34388a6aaa846909 to your computer and use it in GitHub Desktop.
Updates Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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