So I'm trying to write a powershell script that does the following:
I already have constructed my powershell script as following:
Import-Module PSWindowsUpdate
Get-Command –module PSWindowsUpdate
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d
Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot
Which works perfect.
However, depending on some things, it's possible that there are still available updates after the reboot that can be downloaded and installed.
What I want to do is to keep running the script above after each reboot untill there are no more updates left to be downloaded & installed.
What I've found out is the Task scheduler
in Windows that could be handy.
What I also have constructed is a 'logic' to check if there are any updates left (and install them):
$Output = (Get-WUInstall -MicrosoftUpdate -ListOnly) | Out-String
if($Output.Contains("Update"))
{
Write-Host "Updates Available, they will be installed..."
Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot
}else
{
Write-Host "There are no updates available. "
}
ANd the piece code of above also works flawlessly.
My question was to inform in what way I can let this script (or multiple scripts?) run after each reboot untill there are no more updates left...
Thanks
You are on the right track already. Just add a scheduled task to your system that runs powershell.exe with your script as parameter and set the task trigger to "At startup"