Archive

Archive for the ‘Powershell’ Category

Powershell – Executing commands which require quotes and variables is practically impossible!

March 30, 2012 4 comments


Executing commands which require quotes and variables is practically impossible: Microsoft Connect

This is an interesting forum thread about what I’ve spent the last 2 hours researching:  How to properly quote commands with parameters and interpolated paths so that they will execute as a 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 same thing in powershell and this is what you get:


PS C:\Documents and Settings\nunya> “C:\Program Files\Mozilla Firefox\firefox.exe” -CreatProfile myTest
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
Advertisements