Remotely execute .exe with parameters

I’m trying to call a .exe file on remote servers and pass parameters. I’ve tried a few methods, start-process and {&‘dir/file.exe’} and can’t seem to get it right.

here’s my code:

Invoke-Command -Computername $computer -ScriptBlock {Start-Process -Filepath "C:/Scripts/File.Exe" -ArgumentList 'username', 'password', 'action'}

I think it has to do with the differences powershell parses arguments verses cmd.exe, thoughts?

Is this file stored locally on your computer or on the server(s) themselves? Only files local to each server could be executed with this method – otherwise you need to provide a UNC path (e.g., “\COMPNAME\C$\Scripts\File.exe”). Either way, if this is a Windows server, you should be using back-slashes for the path not forward-slashes, although in a lot of cases it won’t matter that much.

Is this an interactive program, or will this result in a purely command-line execution? Only the latter can function with Invoke-Command.

Are you passing in the parameters as variables? If these variables come from the wider script, you need to prefix them in your Invoke-Command block with $using: (e.g., $using:VARNAME)

What does calling this application locally look like?

Thanks for the reply:

  1. Remote computer not on local machine of the powershell script

  2. Execution of the program works in cmd.exe when i call (after cd to correct directory) ./file.exe username password action

Can you give an example of syntax? Are there spaces in any of the arguments you need to pass? Do they involve switches, or is it literally just ‘filename.exe USER PASS ACTION’?

Try adding the -Wait parameter to the Start-Process call, as well. Perhaps the remote non-interactive session is playing a bit funky with how the application is accustomed to behaving.

Open command prompt:

cd /dir of exe file

./file.exe user pass action

application begins to run accepting the 3 parameters from the command line into string args

The only thing I can think of is some kind of permissions issue, I suppose. Most applications should run fine through Invoke-Command unless they don’t have a CLI.

I want to enable the remote session(PS remoting) via Registry, can anyone help.

  1. As it also requires a service to be running, it probably cannot be done entirely with registry settings
  2. Please create a new thread, this is unrelated to the original question. :slight_smile: