Is there any restriction to the number of parameter sets a cmdlet can have? I’ve made a cmdlet which has 56 switch parameters and I want each one to be mandatory in its own parameter set. For some reason powershell groups the (n+1)th with the 1st, the (n+2)th with the 2nd etc, ending up with no more than n parameter sets; if I counted correctly n was 32.
This is what my cmdlet looks like:
[Cmdlet(VerbsCommon.Get, "Foo")]
public class GetFoo : PSCmdlet
{
[Parameter(ValueFromPipeline = true)]
public string ParamA {get;set;}
[Parameter(ValueFromPipelineByPropertyName = true)]
public string ParamB {get;set;}
[Parameter]
public string ParamC {get;set;}
[Parameter(ParameterSetName = "Group1", Mandatory = true)]
public SwitchParameter Param1 {get;set;}
[Parameter(ParameterSetName = "Group2", Mandatory = true)]
public SwitchParameter Param2 {get;set;}
. . .
[Parameter(ParameterSetName = "Group56", Mandatory = true)]
public SwitchParameter Param56 {get;set;}
}
Expected:
PS> Get-Help Get-Foo
Get-Foo -Param1 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
Get-Foo -Param2 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
. . .
Get-Foo -Param56 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
Actual:
PS> Get-Help Get-Foo
Get-Foo -Param1 -Param33 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
Get-Foo -Param2 -Param34 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
. . .
Get-Foo -Param24 -Param56 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
Get-Foo -Param25 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
. . .
Get-Foo -Param32 [-ParamA <string>] [-ParamB <string>] [-ParamC <string>]
I’m breaking my head and can’t see what’s wrong with the way I’ve constructeed the cmdlet; I don’t see this behaviour if I decrease the number of parametersets. Any tips would be appreciated.
It looks like there’s a limit of 32 ParameterSets per cmdlet. See if you can test it out by creating 65 parameter sets and see if -Param65 is in set 1 (with -Param1 and -Param33).
A workaround would be to change your SwitchParameters into a Parameter that takes an Enum containing all of your switch values.