Question in short
How to automate with Windows built-ins (batch/PowerShell) or freely available tools, prefereably command-line, following steps:
- Scan for all currently available updates on WU
- Download and install them right now (i.e. without any throttling/scheduling/backgrounding)
- Restart if necessary, closing whatever doesn't closes automatically.
I'd also like something that triggers the same background mechanism behind existing WU in Setting panel, not something that will use separate infrastructure by setting up its own download locations or whatever.
Background
I have a PC that doesn't have regular restarts or fixed working schedule. WU is running, but all its auto-restart facilities are completely disabled so it won't get in the way of the work at some absolutely inconvenient time. Sometimes a window of opportunity comes up when I can dedicate time to running a full cycle of updates. To do it manually I need to:
- Open WU settings
- Run "Check for updates" to reveal fresh updates missing for any reason
- Click "Download" and then wait arbitrary long time, because apparently this only schedules actual download and both download and installation are heavily throttled depending on PC load
- Wait until process is done and manually restart PC if necessary - trying to use "Update & Restart" from power menu often only installs already downloaded stuff and skips over what is not downloaded
- Restart often reveals previously hidden updates that DO NOT depend on what was just installed - Settings' WU panel just seems to stop displaying new updates after at least one freshly installed requests restart
I'd like to automate all those steps and, if possible, reduce number of restarts.
So far I tried
PSWindowsUpdate3rd party module for PowerShell, but it seems to display different set of available updates - e.g. it offered me to install Silverlight - and whatever it installs does not appear in "View update history" list.
usoclient.exelooks promising, but there's no official documentation for it and from some online examples of people cobbling up some working scripts, it seems there's no reliable way to detect when all updates are done installing and it is time to reboot.
1 Answer
Windows 10 has implemented a new command for installing updates - usoclient.
The previous command WUAUCLT does not work any more.
You will also need a third-party product to shutdown with update and reboot -ShutdownWithUpdates.
Here is how to use it as Administrator:
usoclient ScanInstallWait
usoclient StartInstall
REM Wait 40 mins to allow all the installs to complete
timeout /T 2400
\path\ShutdownWithUpdates.exe /r /fThis method has three problems:
- It's unknown how long we need to wait for the updates to install, as 40 minutes is just arbitrary
- There is no way of knowing if the installed updates have introduced the need for further updates, so the script needs to be run again one or more times
- Too many optional updates may be installed.
References:
The PowerShell method uses the following commands as Administrator:
Install Windows Update Module (one time command) :
Install-Module PSWindowsUpdateCheck and Download the latest updates :
Get-WindowsUpdateInstall the latest updates :
Install-WindowsUpdate
This method also suffers from the above problems number 2 and 3.
4