Options for reducing the number of parameters

This topic contains 3 replies, has 4 voices, and was last updated by  Richard Siddaway 11 months, 4 weeks ago.

  • Author
  • #71635



    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

    Max Kozlov

    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

    Don Jones

    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

    Richard Siddaway

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

You must be logged in to reply to this topic.