You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Binding a parameter via the pipeline can break implicit parameter-set selection #11235
ili101 discovered that binding a parameter via the pipeline can cause PowerShell to select the wrong parameter set under certain circumstances.
The issue can be resolved by designating a default parameter set.
Arguably, PowerShell shouldn't pick a default parameter set at all in this case, but it does:
defensibly with direct arguments,
seemingly incorrectly with conceptually equivalent pipeline input
Note that it is legitimate use case to have an explicit parameter set that has no mandatory parameter (set A below): You may want to group multiple parameters as logically related, even if none of them is individually mandatory.
Steps to reproduce
functionfoo
{
[CmdletBinding()] # DefaultParameterSetName='A' would make the issue go awayParam(
[Parameter(ParameterSetName='A')] $A1,
[Parameter(ParameterSetName='A')] $A2,
[Parameter(ParameterSetName='B',Mandatory)] $B1,
[Parameter(ParameterSetName='B')] $B2,
[Parameter(ValueFromPipeline)] $InputObject
)
$PSCmdlet.ParameterSetName
}
# OK: Argument-less invocation selects 'A'
foo | Should -Be A
# OK: Binding -InputObject by direct argument also selects 'A'
foo -InputObject 1| Should -Be A
# FAILS: Binding -InputObject via the pipeline inexplicably selects 'B'# Just press Enter to answer the prompt.& { 1| foo } | Should -Be A
Expected behavior
All tests should pass.
Actual behavior
The 3rd test fails: It unexpectedly selects set B prompts for a value for -B1.
Expected strings to be the same, but they were different.
String lengths are both 1. Strings differ at index 0.
Expected: 'A' But was: 'B'
changed the title [-]Binding a parameter via the pipeline can break parameter-set selection[/-][+]Binding a parameter via the pipeline can break implicit parameter-set selection[/+]on Dec 2, 2019
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
[-]Binding a parameter via the pipeline can break parameter-set selection[/-][+]Binding a parameter via the pipeline can break implicit parameter-set selection[/+]microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
aolszowka commentedon Nov 16, 2023
Still repros for me; following exactly what this user has written:
microsoft-github-policy-service commentedon Nov 24, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.