2

I am trying to update windows servers remotely with the PS Module PSWindowsUpdate via this scriptblock:

#Will Update Windows, automatically reboot and out the log in the specified directory. This will be done to all listed Servers ForEach ($Index in $Servers) { $Scriptblock = { Invoke-WUJob -Comp $Index -RunNow -Confirm:$false -Verbose -Script { Install-WindowsUpdate -MicrosoftUpdate -NotCategory "SilverLight" -NotTitle "Preview" -AcceptAll -AutoReboot | Out-File C:\PSWindowsUpdate.log } } Invoke-Command -Comp $Index -ScriptBlock $Scriptblock } 

However the task gets created on the Remote PC I am testing this on with ID 4702 "Other Object Access Events". But it never really seems to do anything even though the scheduled task has all the information in it.

I have installed the module on the host pc and remote server, NuGet is installed and TLS 1.2 is enabled as well.

The PSWindowsUpdate.log file is created in (C:) but has nothing in it. The rest of the script just stops some services and boots them up after the supposed update has been done, which also seems to work.

What I also tried was to remotely activate another update script on the server, that is supposed to download the update and install it but I keep getting Access is denied messages, which was expected.

Any other solutions you might have to update multiple windows servers at once or how to get Invoke-WUJob to work would be appreciated!

1
  • I know this is old... We use this very similar to yours and it usually works. Two things I can suggest 1) Did you check the task history for the scheduled job? Did it run? 2) move the logfile out of the C:\. Maybe try c:\temp Commented Jul 25, 2022 at 17:31

2 Answers 2

1

I would try something like this:

ForEach ($Index in $Servers) { $Scriptblock = { Invoke-WUJob -Credential $creds -Taskname WUinstall -Comp $Index -RunNow -Confirm:$false -Verbose -Script { Install-WindowsUpdate -MicrosoftUpdate -NotCategory "SilverLight" -NotTitle "Preview" -AcceptAll -AutoReboot | Out-File C:\PSWindowsUpdate.log } } Invoke-Command -Comp $Index -ScriptBlock $Scriptblock } 

I have had success when adding the -Credential parameter to the command in the past.

1

This one-liner works for me. Does require an elevated powershell.

$ServerVMs = @("DC1","DC2")

Invoke-WUJob -ComputerName $ServerVMs -Script {ipmo PSWindowsUpdate; Install-WindowsUpdate -AcceptAll | Out-File C:\Windows\PSWindowsUpdate.log } -RunNow -Confirm:$false -Verbose -ErrorAction Ignore

Participating Guest VMs need this command run to enable the remote execution of updates:

Install-Module PSWindowsUpdate -Force

Import-Module PSWindowsUpdate

Here's an easy way to look up VMs running on a list of hosts:

$VMHosts= "VMHOST1","VMHOST2","VMHOST3","VMHOST4"

Invoke-Command ($VMhosts){ Get-VM| select vmname }

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.