Double Dash external command prefix not working?

by dmbyer at 2013-02-04 16:29:36

Hi! I’m reading the Powershell 3 Month of Lunches book and am in chapter 4.7, external command. It is stated that prefixing an external command (like ping) with a double dash ("–") will automatically pass the entire command through to cmd.exe, bypassing Powershell’s parsing mechanism. When I attempt to duplicate this, I receive an error:
PS C:\Users\daniel> --ping localhost
At line:1 char:3
+ --ping localhost
+ ~
Missing expression after unary operator ‘–’.
At line:1 char:3
+ --ping localhost
+ ~~~~
Unexpected token ‘ping’ in expression or statement.
+ CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator


I’ve tried searching Google for some information but can’t seem to find anything relevant (most results are for unary operator ‘-’, just a single dash; those that I can find with double dash don’t seem to be related or contain pertinent information. I’ve also confirmed I’m running PS3. I’ve tried this in both just the powershell and the ISE. Does anybody have some insight? Thanks!
by DonJ at 2013-02-04 16:58:15
Yeah, not quite. There was a syntax change on RTM and we didn’t catch that in the book damnit. I’ll do an errata. Anyway… you issue the command FIRST, and then you can include the new operator to have it ignore the REST of the line. I’m on my phone - but I’ll look it up for you and post back tomorrow.
by DonJ at 2013-02-04 16:59:43
It’s…

&"H:\backup\scripts\sbrun.exe" --% -mdn ( sbvol -f \?\GLOBALROOT\Device\HarddiskVolumeShadowCopy43 \?\E: : sbcrypt -50 : sbfile -wd H:\backup\backups )

So the --% says "stop parsing here and just pass it along."
by dmbyer at 2013-02-04 17:28:29
Oh awesome, thank you Don! And a reply within 30 minutes…? I’ll definitely be keeping an eye out for more of your books! Not for just that reason of course, but because so far I am very happy with it! =)

Thanks again.