Although I generally use pre-baked images of Windows Servers I occaisionally run into a situation where I have to set one up from scratch and go through the incredibly tedious process of checking for updates, installing them and then rebooting. Many, many, many times.
I am trying to write a simple script to automate this.
The checking and installing updates is straightforward:
wuauclt.exe /detectnow /updatenow
And the rebooting is just as straightforward:
shutdown /r /t 0
But what I would like to do is create a PowerShell workflow that continues running after reboot, running the above commands in a loop.
The areas I have not figured out are:
Use an update searcher to check for pending updates:
$criteria = "Type='software' and IsAssigned=1 and IsHidden=0 and IsInstalled=0"
$searcher = (New-Object -COM Microsoft.Update.Session).CreateUpdateSearcher()
$updates = $searcher.Search($criteria).Updates
if ($updates.Count -ne 0) {
# $updates pending
} else {
# system up-to-date
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.