Q. How do I quote command parameters for an external command in PowerShell?

Don Jones

May 26, 2010

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like