Skip to content

Instantly share code, notes, and snippets.

@pronichkin
Last active September 23, 2020 02:08
Show Gist options
  • Save pronichkin/3757ec3bc0d3bfceb502337ae228dd6a to your computer and use it in GitHub Desktop.
Save pronichkin/3757ec3bc0d3bfceb502337ae228dd6a to your computer and use it in GitHub Desktop.
$Session = New-Object -ComObject 'Microsoft.Update.Session'
$Searcher = $Session.CreateUpdateSearcher()
$Query = 'IsInstalled = 0 or
IsInstalled = 0 and DeploymentAction = ''OptionalInstallation'''
$Search = $Searcher.Search( $Query )
If
(
$Search.Updates.Count
)
{
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $Search.Updates
$Download = $Downloader.Download()
$Installer = $Session.CreateUpdateInstaller()
$Installer.Updates = $Search.Updates
$Install = $Installer.Install()
If
(
$Install.RebootRequired
)
{
Restart-Computer -Confirm
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment