Q. How do I quote command parameters for an external command in PowerShell?
May 26, 2010
A. Normally, PowerShell can run external commands if you simply type the command name:
Ipconfig
Ping Bing.com
Nslookup
However, some commands require extensive command-line parameters. When those parameters start to involve quotation marks, it can get tricky to get PowerShell to properly parse the arguments and pass them to the external command. For example, consider this simple command:
Wdsutil /replace-image /image:"MyImage"
The easiest way to run it to use PowerShell’s Start-Process cmdlet, which can accept the complete argument as a here-string:
Start-Process WdsUtil -argument @"
/replace-image /image:"MyImage"
"@
Note that you have to type it just like this: The @" must be the last thing on the first line, then you type whatever arguments you want passed, and finally the closing "@ must be the first two characters on the next line.
There’s a more technical discussion of this trick at http://wiki.poshcode.org/FAQ/Problems_and_Gotchas/Quoting_and_Legacy_Commands, which also discusses how PowerShell parses arguments for external commands.
About the Author
You May Also Like