Powershell doesn't seem to cope with a large number of parameter sets in the cmdlet

Is there a limit to the number of parameter sets a cmdlet can have? I made a cmdlet that has 56 switch parameters, and I want each of them to be mandatory in its own set of parameters. For some reason, powershell groups the (n + 1) th with the 1st, the (n + 2) th with the second, etc., ending with no more than n parameter sets; if I counted n correctly, there were 32. This looks like my cmdlet:

[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 rack my brains and don’t see what happened with the way I created the cmdlet; I do not see this behavior if I reduce the number of parameter sets. Any advice would be appreciated.

+4
source share
1 answer

It appears that there is a limit of 32 parameters for each cmdlet. See if you can test it by creating 65 sets of parameters and see if -Param65 is set in set 1 (with the -Param1 and -Param33 options).

A workaround would be to change the SwitchParameters parameters to a Parameter that takes an Enum containing all of your switch values.

 Get-Foo -ParamD <EnumParams1To56> [-ParamA <string>] [-ParamB <string>] [-ParamC <string>] 
+2
source

All Articles