How can I start Windows Updates on 10 Windows 2016 servers remotely using Powershell
I have 10 domain joined Windows 2016 servers. I need to run Windows updates on them, I don't want to logon on to each of them, and then manually start Windows Updates.
I found that you can do it with;
Install-Module PSWindowsUpdate
But I don't know how exactly.
**** Update; thanks to duenni, this was my final solution. Install PSWindowsUpdate modules and then;
Set-Item WSMan:\localhost\Client\TrustedHosts –Value * -Force
$Script = {import-module PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install -Verbose -AutoReboot | Out-File C:\PSWindowsUpdate.log}
Invoke-WUjob -ComputerName s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20 -Script $Script -Confirm:$false -RunNow
Solution 1:
As per Release Notes (click on "Package Details") the command Invoke-WUInstall
has been replaced by Invoke-WUJob
in Version 2.0.0.
Try
$Script = {import-module PSWindowsUpdate; Get-WindowsUpdate -AcceptAll -Install | Out-File C:\PSWindowsUpdate.log}
Invoke-WUjob -ComputerName $computer -Script $Script -Confirm:$false -RunNow
Solution 2:
As a direct equivalent to Invoke-WUInstall you could actually invoke Get-WUInstall using Invoke-Command.
Make sure you have the latest PSWindowsUpdate.
Change PowerShell’s Execution Policy to RemoteSigned. The RSEP allows PowerShell scripts as long as they are signed by a trusted publisher. Type
Set-ExecutionPolicy RemoteSigned
and press Enter. Confirm when prompted.For PS 2.0 Import-Module PSWindowsUpdate (not needed after 3.0)
GetWUInstall
supports many nice things, but by far the most useful are:
Get-WUInstall –MicrosoftUpdate –ListOnly
--> will list available updates from the Microsoft Update serversGet-WUInstall –MicrosoftUpdate
--> will ask for each update if to install or not (very useful in recent times)Get-WUInstall –MicrosoftUpdate –AcceptAll
--> automatically accept alladding –
AutoReboot
--> will also reboot after updating
Many more things are supported like hiding, un-hiding or installing specific KBs. You can use Help Get-WUInstall –full
to see all supported features.