Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Executable from Powershell script with parameters

So I have a powershell script that is supposed to run an executable with an argument to pass to set which method I want to run, and I need to pass a parameter, which is a directory to a config file. So this is what I have

Start-Process -FilePath "C:\Program Files\MSBuild\test.exe" -ArgumentList /genmsi/f $MySourceDirectory\src\Deployment\Installations.xml 

/f is the shortname and file is the long name for my attribute... I get an error in powershell telling me that a positional parameter cannot be found for /f or /file.

Any thoughts?

like image 364
Nerd in Training Avatar asked Aug 07 '14 15:08

Nerd in Training


People also ask

How do you use Runas in PowerShell?

Step 1: Press the Windows + R keys together to bring up the Run dialog box. Step 2: Type the PowerShell in the box and click OK button. A normal Window PowerShell will launch as a current user. Step 3: Type the command start-process PowerShell -verb runas and press "enter" key.

How do I run an exe from an argument?

Click on any folder on your desktop, up one level, and do the same as is in picture. Press Win+R , write cmd.exe /k cd desktop , hit enter, write program name and arguments. run it and write program name and arguments.


Video Answer


2 Answers

Try quoting the argument list:

Start-Process -FilePath "C:\Program Files\MSBuild\test.exe" -ArgumentList "/genmsi/f $MySourceDirectory\src\Deployment\Installations.xml" 

You can also provide the argument list as an array (comma separated args) but using a string is usually easier.

like image 78
Keith Hill Avatar answered Sep 20 '22 01:09

Keith Hill


I was able to get this to work by using the Invoke-Expression cmdlet.

Invoke-Expression "& `"$scriptPath`" test -r $number -b $testNumber -f $FileVersion -a $ApplicationID" 
like image 39
Nerd in Training Avatar answered Sep 23 '22 01:09

Nerd in Training