Options for reducing the number of parameters

Welcome Forums General PowerShell Q&A Options for reducing the number of parameters

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

 
Participant
1 year, 5 months ago.

  • Author
    Posts
  • #71635

    Participant
    Points: 1
    Rank: Member

    Hi,

    I'm building a PowerShell module for an internal Rest-Api. My problem is that one particular controller offers a ton of optional properties to be set, so my function would end up with 50+ parameters.

    What options do I have to reduce the number of parameters? I could use objects to group some of the parameters, but then users would have to read the documentation to know what the objects look like. (Or is it possible to get IntelliSense on the properties of a pscustomobject?)

    I don't really see a great way of handling this. Any ideas?

  • #71638

    Participant
    Points: 0
    Rank: Member

    if part of parameters doesn't mean explicit use (credentials, connection options, etc)
    You can setup your code like PSSessionConfiguration, i.e. move options to different cmdlet and use it internally or
    something like

    $session = new-specialsession -options1 -options2 ...
    invoke-specialapi -session $session -additional -option
    
  • #71639

    Keymaster
    Points: 1,644
    Helping HandTeam Member
    Rank: Community Hero

    I'd add that 50 isn't so bad. Look at the ADUser commands – they have a ton. I'm not sure I'd see reduction as a goal, and certainly not "bundling" parameters and making them harder to discover and understand.

  • #71651

    Participant
    Points: 0
    Rank: Member

    Also look to see if defining parameter sets can help reduce the number of parameters you're dealing with at one time

The topic ‘Options for reducing the number of parameters’ is closed to new replies.