I need to schedule an unattended weekly out of hours download & install of windows updates and then reboot of a Windows Server 2016 box. How can I do this? Can it be done from the command line?
Similar question regarding Windows 2003 Schedule Windows Updates exclusively on a specific work day (and time)?
You should be able to do it via Group Policy, under "Computer Configuration"->"Administrative Templates"->"Windows Components"->"Windows Update", changing the policy setting there.
Alternatively, you can do it by runningwuauclt /detectnow
to check if there are any Microsoft Updates outstanding for installation. Putting that into a scheduled task should give you what you want.Edit: It seems that
wuauclt
no longer works in Windows 10 (and presumably Server 2016). Instead, you can either create a script based on%windir%\System32\en-US\WUA_SearchDownloadInstall.vbs
, which is used bysconfig
, or you can download the script from https://gallery.technet.microsoft.com/scriptcenter/VB-Script-to-Check-and-620579cd and check if it works for you. (Note that the latter will skip any updates that require user input as that won't be possible during an unattended update.)There is indeed a command line tool that is exactly built for your use case - have a look at WuInstall (http://www.wuinstall.com) - it is a commercial product intended for companies with 50 machines and more but you can always download a free trial version to test in your environment
You can put wuinstall.exe in a batch script on the same machine or you can call it remotely via psexec
In the simplest case (you will also probably need a few more options for pruction environments) just write your batch script calling
and kick it of with a task scheuduler of your choice at the time you want to update.
With the /reboot_if_needed option it is possible to reboot the machine unattended after the update, and the /rebootcylce option even reboots multiple times until all updates are installed.
WuInstall basically puts the whole Windows Update API and its most common use cases in one central command line tool - There are quite a few more options to script and select windows updates, check out the technical documentation under: https://wuinstall.atlassian.net/wiki/display/WD/WuInstall+HowTo