Multiple matches for byproperttyname

by stromnessian at 2013-02-17 08:09:42


I’m probably missing something really obvious, but what happens if you have a cmdlet that has multiple parameters that accept input by property name and you pipe an object to it that has more than one matching property name?

Many thanks
by JeffH at 2013-02-17 08:41:40
Are you just asking or have you run into this? I don’t think that is possible because I don’t think you can have an object with duplicate property names.
by JeffH at 2013-02-17 08:43:00
Or maybe this is what you are asking: If the object has properties Name, and Computername and the cmdlet you are piping to has -Name and -Computername, then each property is bound to the corresponding parameter.
by stromnessian at 2013-02-17 09:06:24
Yes, that’s what I meant. I experimented with the Get-Process cmdlet, piping in custom objects. I created three objects: test1 with name and ID, test2 with just name, and test3 with just ID. I made the name property match one process (e.g. powershell) and the ID match another (e.g. 528 (wininit)) and found that test2 and test3 would both produce the expected result, matching name and ID respectively, but with test1 only the matching name would be output. I’m guessing it’s because Name and ID are from two different parameter sets and only one can be matched?

Thanks again.
by JeffH at 2013-02-17 09:12:43
I would expect that to be the case and you should be able to test that.
by stromnessian at 2013-02-17 12:48:44
Thanks Jeff. Yes, it looks like it tries the default parameter set first. Was just curious, probably never run into it in reality :slight_smile: