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!

Unbuckle
  • 21
  • 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 – uSlackr Jul 25 '22 at 17:31

1 Answers1

0

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.