The new --% parameter

by willsteele at 2012-10-16 15:07:02

I have seen a few posts on this new --% parameter. Does anyone have details on it? I checked help but it’s not in there yet.
by Makovec at 2012-10-16 16:06:36
It’s related to parsing command lines with "strange" parameters/values like $%-. When PowerShell v3 see –% it change it’s parsing mode.

[quote]Easier Reuse of Command Lines From Cmd.exe

The web is full of command lines written for Cmd.exe. These commands lines work often enough in PowerShell, but when they include certain characters, e.g. a semicolon (:wink: a dollar sign ($), or curly braces, you have to make some changes, probably adding some quotes. This seemed to be the source of many minor headaches.

To help address this scenario, we added a new way to “escape” the parsing of command lines. If you use a magic parameter --%, we stop our normal parsing of your command line and switch to something much simpler. We don’t match quotes. We don’t stop at semicolon. We don’t expand PowerShell variables. We do expand environment variables if you use Cmd.exe syntax (e.g. %TEMP%). Other than that, the arguments up to the end of the line (or pipe, if you are piping) are passed as is. Here is an example:

PS> echoargs.exe --% %USERNAME%,this=$something{weird}
Arg 0 is <jason,this=$something{weird}>[/quote]
Quote from: … tures.aspx
by Aleksandar at 2012-10-17 10:30:55
It’s documented in the online version of about_Parsing help topic ( … 47892.aspx). Search for "STOP PARSING: --%" section.
Unfortunately, when you use Update-Help you don’t get that updated version.