Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell - Start-Process and Cmdline Switches

I can run this fine:

$msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe"  start-process $msbuild -wait 

But when I run this code (below) I get an error:

$msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /v:q /nologo"  start-process $msbuild -wait 

Is there a way I can pass parameters to MSBuild using start-process? I'm open to not using start-process, the only reason I used it was I needed to have the "command" as a variable.

When I have
C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /v:q /nologo
on a line by itself, how does that get handled in Powershell?

Should I be using some kind of eval() kind of function instead?

like image 934
BuddyJoe Avatar asked Mar 16 '09 16:03

BuddyJoe


People also ask

What is PowerShell start-process?

The Start-Process cmdlet allows you to run one or multiple processes on your computer from within PowerShell. It's designed to run a process asynchronously or to run an application/script elevated (with administrative privileges).

How do I start and end a process in PowerShell?

Find the name of the process and record the PID or image name (i.e., notepad.exe). To kill the process on PowerShell, use any of the following commands: To gracefully kill the notepad process with pid: taskkill /pid 13252. To forcefully kill the notepad process with pid: taskkill /pid 13252 /f.

What is the alias which will start a process in PowerShell?

You can name 'Start-Powershell' (name of the Function) whatever you like. This is your new "Alias" which works in your user environment and with auto-completion.

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.


2 Answers

you are going to want to separate your arguments into separate parameter

$msbuild = "C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" $arguments = "/v:q /nologo" start-process $msbuild $arguments  
like image 136
Glennular Avatar answered Sep 22 '22 04:09

Glennular


Using explicit parameters, it would be:

$msbuild = 'C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe' start-Process -FilePath $msbuild -ArgumentList '/v:q','/nologo' 

EDIT: quotes.

like image 25
EBGreen Avatar answered Sep 19 '22 04:09

EBGreen