Running batch file on Remote Computers using PowerShell 2.0

Question:

I am trying to run a exe on remote machines which would basically uninstall a product agent. below is the code:

It doesn’t work. I ended up removing the program from the host computer itself 🙂

Alternate Option: I created a batch file with the command line:

It seems the above can also be achieved using Invoke-Command.

Apparently, it does not accept batch file. I would like to keep it as simple as possible.

Currently I am using PSExec for installing and uninstalling the program. Do I need to enable PS Remoting (WinRM) on every remote machine on whom I need to execute scripts using PowerShell?
Can someone please help? Thanks in advance.

Answer:

This command should execute successfully:

but you will need to enable CredSSP authentication on all machines by running these two commands on each machine:

Source:

Running batch file on Remote Computers using PowerShell 2.0 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply