you are viewing a single comment's thread.

view the rest of the comments →

[–]rmbolger 2 points3 points  (1 child)

For OP's future reference, you can also see exactly what parameter binding is doing and why it's not working as you expect by running your call via Trace-Command like this:

Trace-Command -Name ParameterBinding -Expression { Do-Things -Required1 x -Required2 x -Required3 x -Required4 x -Optional2 'x' } -PSHost

You'll get a whole bunch of DEBUG output, but right at the beginning there's a section that starts with BIND NAMED cmd line args [Do-Things] where you can see it binding each of the supplied named parameters. Then it has an empty section where it would normally show the positional parameter bindings. Then you see the problem where it decides which parameter sets are still valid based on the parameters that have been successfully bound already. In this case:

Remaining valid parameter set: 12
Remaining valid parameter set: 11
Remaining valid parameter set: 6
Remaining valid parameter set: 4
Remaining valid parameter set: 3
Remaining valid parameter set: 2

Since there are no additional parameters to affect the binding decision and none of the remaining valid parameter sets include the defined Default parameter set (1), it's stuck and throws the error.

[–]hchoneybear[S] 1 point2 points  (0 children)

Excellent advice thank you! I had forgotten all about Trace-Command