Skip to content

Instantly share code, notes, and snippets.

@curious-username
Created April 19, 2023 05:43
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 curious-username/6c46711c759ea54fc85952ca67ea782f to your computer and use it in GitHub Desktop.
Save curious-username/6c46711c759ea54fc85952ca67ea782f to your computer and use it in GitHub Desktop.
another readme
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software'")
if ($SearchResult.Updates.Count -eq 0) {
Write-Output "No updates available"
} else {
$UpdatesToInstall = New-Object -ComObject Microsoft.Update.UpdateColl
foreach ($Update in $SearchResult.Updates) {
$UpdatesToInstall.Add($Update)
}
$Downloader = $UpdateSession.CreateUpdateDownloader()
$Downloader.Updates = $UpdatesToInstall
$Downloader.Download()
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $UpdatesToInstall
$InstallationResult = $Installer.Install()
if ($InstallationResult.RebootRequired) {
Write-Output "Reboot required"
Restart-Computer
} else {
Write-Output "Updates installed successfully"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment