Whilst PowerShell 2 is by-and-large backwards compatible, I’ve learned at least one breaking exchange that appears to be undocumented: the behaviour of argument parsing when calling another executable seems to have changed.

Previous behaviour:

clip_image002

PowerShell has effectively parsed the argument as if it were calling a PowerShell speech: splitting it into two parts along the colon, and passing the second part ‘intact’ because it was quote wrapped.

New behaviour in v2:

image

PowerShell has treated the arguments as completely opaque and passed them to the exe by ‘normal’ command line parsing semantics (split on spaces etc…). It has not split the argument along the colon (which was the breaking exchange for us). In the second case, because the argument didn’t start with a quote (it starts with ‘-test’) the argument is broken in half at the space.

I reflect this is a excellent exchange, in that PowerShell shouldn’t make assumptions about how the exe you are calling likes it’s parameters (I got terribly burnt that way trying to call an SSIS package). But it’s certainly one to watch out for.

 

PS: Not sure at all about this behaviour, which is the same in both v1 and v2:

image

Surely the fact you pass the argument as a string variable indicates you want it as one argument. Surely.


Check it out:Cup(Of T)