Pass PowerShell arguments to Process.Start

Question:

I am trying to convert some of my bat scripts over to C#.
I have the entire program ported except for the PowerShell execution line.

To keep things simple, I was trying to just call the PowerShell command from cmd.
I am able to do so but its not taking the complex arguments and parameters that go along with the PowerShell command.

Here is the command if I run directly from cmd or bat file.

I was using this code to invoke cmd and run my powershell command.

I get this error
“Cannot process the command because of a missing parameter. A command must follow -Command.”

As you can see there are a lot of arguments in this PowerShell command.

Is there an easier way to do this? or I am just missing something simple?

Answer:

In your original PowerShell line, the Command is surrounded by double quotes.

Try this:

Notice the use of \" escape sequences to add the missing double quotes that are present in your original command line.

Source:

Pass PowerShell arguments to Process.Start by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply