powershellstart-process

Powershell ArgumentList with string


I want to run a powershell process with a command list. I'm having an issue with using a string in an argumentlist with a command list.

This is what I try to run:

Start-Process Powershell -ArgumentList '-command "$var = "test""'

But it results in:

The term 'test' is not recognized as the name of a cmdlet, function, script file, or operable program.

I tried the same with:

Start-Process Powershell -ArgumentList '-command "$var = `"test`""'

But also with a negative result.

Any ideas how to solve this issue?


Solution

  • Perhaps surprisingly, PowerShell's CLI (powershell.exe) requires embedded " chars. to be escaped as \", not as `":

    Start-Process Powershell -ArgumentList '-command "$var = \"test\""'