tags:

views:

62

answers:

1

It seems that somebody has subtly changed the way that parameter switches are parsed on powershell. On some machines "split-path c:\x\y --parent" works. On some it fails. Can anyone tell me a) what causes the difference and b) how can I stop it?

+1  A: 

Switch parameters should work in the same way in both V1 and V2 (that means -parent is the right syntax).

In your case --parent should be bound to an parameter as a string. It should not be interpreted as a switch. You can test the binding via Trace-Command

Trace-Command parameterbinding -Expression { split-path c:\x\y --parent} -PSHost

Further info:

Considering --: every string behind -- is interpreted as argument, no matter if it looks like a switch.

[14]: function test { 
    param([switch]$sw, [string]$str) 
    write-host switch is $sw
    write-host str is $str 
}
[15]: test 1
switch is False
str is 1
[16]: test -sw
switch is True
str is
[17]: test -- -sw
switch is False
str is -sw
stej
Completely agree that single dash is correct. The problem is, we've got 100-odd scripts that use double dash and it works on most machines in the office.
Julian Birch
What is the output from `Trace-Command`?
stej