I’ve spent the last 2 hours reading an interesting bug report/forum thread about how executing commands which require quotes and variables in PowerShell is difficult (this was originally posted on Microsoft Connect, which no longer exists; replaced with archive.org link). I’m trying to understand how to properly quote commands with parameters and interpolated paths so that they will execute as a single command. Doesn’t seem like it should be so hard. Here is an example of the code I’m working with:
The command I’m trying to run:
C:\Program Files\Mozilla Firefox\firefox.exe -createprofile myTest
Here is what works in MS-Dos / Windows XP command prompt:
"C:\Program Files\Mozilla Firefox\firefox.exe" -CreateProfile myTest
However, run the PowerShell version of the same command,
PS C:\Documents and Settings\nunya> “C:\Program Files\Mozilla Firefox\firefox.exe” -CreatProfile myTest
and this is what you get:
You must provide a value expression on the right-hand side of the ‘-‘ operator.
At line:1 char:48Unexpected token ‘CreatProfile’ in expression or statement.
At line:1 char:49Unexpected token ‘myTest’ in expression or statement.
At line:1 char:62
Originally published: 03/30/2012
Last Updated: 11/13/2018