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:
- How to check for whether the updates have completed.
- How to test for no remaining updates available to install (AKA Windows is fully updated and the script can stop).
Use an update searcher to check for pending updates: