Parameter binding issue in PowerShell


I have this PowerShell cmdlet:

And here is the help for this cmdlet:

Looking at the code and help I would think I could use the cmdlet like this:

But for both of these I get:

Question 1: Should PowerShell be able to bind to parameter sets s2 and s3 in my two cases?

That means that there was not time to implement it for version 2 of PowerShell, or they did not uncover this issue.

Question 2: Is there something wrong with my reasoning here? Should parameter binding fail in these cases?

I found something that may be directly related to my issue here in the PowerShell documentation:

There is one case where Windows PowerShell cannot use the default parameter set even if a default parameter set name is specified. The Windows PowerShell runtime cannot distinguish between parameter sets based solely on object type. For example, if you have one parameter set that takes a takes a string as the file path, and another set that takes a FileInfo object directly, Windows PowerShell cannot determine which parameter set to use based on the values passed to the cmdlet, nor does it use the default parameter set. In this case, even if you specify a default parameter set name, Windows PowerShell throws an ambiguous parameter set error message.


Your logic is correct, Powershell should be able to figure out the parameter set based on your function definition and example usages.

Apparently Powershell v2 simply did not have robust enough logic for this. It works as expected in Powershell v3, though, which is further confirmation that it’s a shortcoming/bug in v2.


Parameter binding issue in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply