Need to run .exe with parameters on multiple remote machines

I need help with a method to run a .exe with parameters for a silent install on multiple remote PC’s.

If I was to run this executable manually on each PC it would look like: \server\share\program.exe /S /v/qn

Using Invoke-Command you can execute commands on other computers by passing the computer names to the -ComputerName parameter.

Can you please give me an example? I have tried several iterations of Invoke-Command without success.

What have you tried and what error messages have your attempts brought?

An example of using it could be something like:

Invoke-Command -ComputerName server1,server2 { Start-Process -FilePath "c:\myapp\myapp.exe" -ArgumentList "arg1", "arg2", "arg3" }

You could do this a couple ways depending on if CredSSP is enabled to get over the second hop problem. Here’s a scripting guy article on CredSSP.

If it is enabled you could execute the program directly off the server share like this:

$creds = Get-Credential

Get-Content yourcomputerlist.txt | Invoke-Command -ScriptBlock {& cmd.exe /c "\\server\share\program.exe /s /v /qn" } -Credential $creds -Authentication Credssp

But at my work we don’t have that luxury so we have to copy the file local and execute like this:

Get-Content yourcomputerlist.txt | ForEach-Object {

    Copy-Item -Path "\\server\share\command.exe" -Destination "\\$_\c$\somefolder" 

    Invoke-Command -ComputerName $_ -ScriptBlock { & cmd.exe /c "c:\somefolder\program.exe /s /v /qn" }
}

I was doing a variation of the second option by copying it locally and then running it. However, it just returns “c:\somefolder\program.exe /s /v /qn” and nothing happens on the remote machine. I am guessing it may be the .exe. Thank you for your replies.

Hmm? I use this all the time. I use PS v3 and v4 but haven’t tried it on v1 or v2, not sure if there’s a difference there. Also it’s important to have the ampersand (&) in there so powershell knows you’re running a command. Otherwise it will just interprets it as a string and echos it back to you. Is your program something common like a KB or an Adobe update? If so, chances are I’ve run it before.

@Jack Neff.

I want to perform the same activity, but can you help me with the below order:

  1. I need to stop a particular process, CcmExec.exe
  2. Rename the folder C:\Windows\ccmsetup as C:\Windows\ccmsetup_old
  3. Copy-Item -Path “\server\share\command.exe” -Destination “\$_\c$\somefolder”
  4. Invoke-Command -ComputerName $_ -ScriptBlock { & cmd.exe /c “c:\somefolder\program.exe /s /v /qn” }

Can you help me with the powershell for this ?

Invoke-Command -ComputerName $_ -ScriptBlock {
Get-Process ccmexec.exe | Stop-Process -Force
Rename-Item C:\Windows\ccmsetup C:\Windows\ccmsetup_old
& cmd.exe /c “c:\somefolder\program.exe /s /v /qn”
}