Windows Updates Remotely

Hello all, trying to get a process for windows updates remotely.
Here is my code:

Install-Module PSWindowsUpdate

Add-WUServiceManager -MicrosoftUpdate

Invoke-WUInstall -ComputerName TRJWIN10-9 -Script {ipmo PSWindowsUpdate; Get-WUInstall -AcceptAll | Out-File C:\PSWindowsUpdate.log }
-Confirm:$false –Verbose

This will prompt me for a

And everything I put it in gives the error:
Invoke-WUJob : Cannot convert ‘System.String’ to the type ‘System.Management.Automation.SwitchParameter’ required by parameter ‘RunNow’.

Any tips would be appreciated.

Per the documentation, Invoke-WUInstall is an old command that has an alias for Invoke-WUJob:

PowerShell Gallery | PSWindowsUpdate

If you look at this example, Invoke-WUJob has a parameter for -RunNow which is the prompt you are getting for the alias command Invoke-WUInstall. Look at the steps in this guide to see if it works as expected:

How to use PowerShell to manage Microsoft updates on Windows - TechRepublic

As a side note, $true should work for the RunNow prompt.

Now I am getting a “connecting to remote server failed. WinRM cannot complete the operation.” Is it accessible over the network, firewall exception for WinRM… etc. Firewall is off, it is pingable, and a firewall exception is on. WinRM Service is running too.

Looks like you need to enable PSRemoting on the remote systems. Google that. Also, on the system running the script, make sure you have Trusted Hosts enabled for the WinRM Client. Google that as well.

I have done both already.
winrm set winrm/config/client ‘@{TrustedHosts=“TRJWIN10-9”}’
As well as updating execution policy,
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force

I ended up doing all commands I just replied with on remote computer, not it’s giving me "The network path was not found. (Exception From HRESULT: 0x60070035). I tried IP instead of TRJWIN10-9, still nothing. The machine is pingable. Would it matter if it’s a virtual machine?

Being a VM should not matter. I do all my testing on VM’s in my lab and for all intensive purposes, they act “virutally” the same as a physical box :slight_smile:

PowerShell remote can be a finicky beast. Here are the general rules I use in troubleshooting PS remoting:

The system running the script must have Trusted Hosts enabled
The remote system must be accessible by hostname, IP addresses will NOT work
The remote system must respond to a ping
PowerShell Remoting must be enabled on the remote system
Access to C$ on the remote system - as in "dir \\hostname\c$" 
Access to the Remote Registry on the remote system (remote registry service enabled)

Maybe this will help you get it figured.

Sorry for the late reply, got really busy with some other stuff. I took a look at this again, and
1.Trusted hosts has been set
2.Remote system is accessible through hostname(file explorer, pings, and the dir \hostname\c$)
3.PSRemoting has been enabled.
I did not have Remote Registry enabled on the remote client, so I have just enabled that. I am now stuck at this error again:
Invoke-WUJob : Cannot convert ‘System.String’ to the type ‘System.Management.Automation.SwitchParameter’ required by parameter ‘RunNow’.

I have also tried
Invoke-WUJob -ComputerName TRJWIN10-2 -Script {ipmo PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot} -RunNow -Confirm:$false
But it says it cannot find the file specified, referring to -Script {ipmo PSWindowsUpdate;…

Do you have any other tips?

Sorry, I don’t have that module installed so I am unable to test in any way. Perhaps one of the PS Ninjas on this site can help.

How would I go about getting to them?

Rob Simmers who has already replied is one.

It looks like it does not like your -Confirm:$false. It wants a Switch Paramater which means the argument is valid as long as the argument is there, there are no settings for the argument and you are feeding it $False. Have you tried running without the -Confirm argument?