Author Posts

May 29, 2017 at 12:38 pm

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?

May 29, 2017 at 1:30 pm

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

May 29, 2017 at 1:53 pm

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.

May 29, 2017 at 4:32 pm

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