Query regarding limit on maxmimum number of ParameterSets for powershell cmdlet?

Welcome Forums General PowerShell Q&A Query regarding limit on maxmimum number of ParameterSets for powershell cmdlet?

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 weeks, 1 day ago.

  • Author
    Posts
  • #112691

    Participant
    Points: 0
    Rank: Member

    Hi,

     

    Can anyone please confirm if there is official limit on the maximum number of ParameterSets for a custom cmdlet? For our powershell module, we are facing issue in the cmdlets when the number of ParameterSets exceeds beyond 32.

     

    On the basis of this, I have few questions:

    1.) Is 32 the limit of maximum number of parametersets that a cmdlet can have?

    2.) Is there any work around for this issue?

    3.) Is there any plan to increase the number of parameterset in future powershell releases?

     

    thanks,

    Vinay Ravish

  • #112738

    Participant
    Points: 0
    Rank: Member

    My initial reaction is that seems like way too many parameter sets for a single function and that you should be using a more modular approach. This is the only doc I see with a quick search that doesn't have any indication of a limitation:

    https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.parameterattribute.parametersetname?view=powershellsdk-1.1.0

    Once you get beyond 32, what is the behavior? Are they being ignored? Are you getting errors? You'll need to gather as much detail as possible and open an issue here:

    https://github.com/PowerShell/PowerShell/issues

    • #112867

      Participant
      Points: 0
      Rank: Member

      Issue statement:
      I have a Get cmdlet, which has a default parameterSet named as "All". As per our implementation, any "Get" cmdlet in our module should run without any parameters(because there are no mandatory parameters under "All" ParameterSet). This rule is followed by all our Get cmdlets and cmdlets worked fine. But after the addition of 33rd parameterSet, "Get" cmdlet start asking for mandatory parameter from a parameterSet(just an observation: last parameterset in sequence). So cmdlet execution basically switched from default parameterSet (i.e. "All") to another parameterSet(last parameterset in sequence) and asks the mandatory parameter specified in that particular parameterSet.

      Expected behavior:
      C:\> Get-xxxEquipmentManufacturingDef
       cmdlet should return objects of of type "EquipmentManufacturingDef". This cmdlet worked fine until the parameterSets were less than 32.
      New Behavior which is causing issue:
      C:\> Get-xxxEquipmentManufacturingDef

      cmdlet Get-xxxEquipmentManufacturingDef at command pipeline position 1
      Supply values for the following parameters:
      EquipmentTpmCapProvider:

  • #112886

    Participant
    Points: 1
    Rank: Member

    You need to explicitly specify the default parameter set in the cmdletbinding statement:

    [CmdletBinding(DefaultParameterSetName = 'All')]
    param(
    # ...
    )

    But in all honesty you probably need to look at breaking that function into several pieces. 32 parameter sets is getting to be far too many; most standard cmdlets have less than 10 sets in total, and a majority of them only have 4 or less.

    One function for one task. 🙂

You must be logged in to reply to this topic.