Author Posts

February 26, 2014 at 5:07 am

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

February 27, 2014 at 4:01 am

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

February 27, 2014 at 4:51 am

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

February 27, 2014 at 5:19 am

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" }

February 27, 2014 at 2:20 pm

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" }
}

February 28, 2014 at 5:20 am

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.

February 28, 2014 at 5:21 pm

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.

September 3, 2015 at 5:07 am

@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 ?

September 4, 2015 at 12:11 am

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"
}