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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With