Script Parameter Sets

I’m not sure how you’d pull it off from a UI perspective, but it’d be awesome if PSU could support parameter sets.

For example, I have a script with parameters defined like this:

# A numeric employee ID.
[Parameter(Mandatory, Position=0, ParameterSetName='id')]
[int] $Id,

# If specifying an ID, whether to include direct reports of that employee..
[Parameter(Position=1, ParameterSetName='id')]
[switch] $IncludeReports = $false,

# The date that employees were last modified.
[datetime] $Since = (get-date).Date,


# The date that employees were last modified.
[switch] $Active

So you can specify -Id and optionally -IncludeReports, or -Active, or -Since and a date etc.

Perhaps the parameter parser could break these out into radio groups and let you just specify the parameters for the group whose radiobutton is selected? And honour the DefaultParameterSetName property so PSU knows which radio button to select by default.

I totally get how hard this would be to implement. :slight_smile:

We certainly could implement this. We could have tabs for each parameter set similar to Show-Command

Nice! Tabs could work but to me they always feel like you have to fill out each tab, rather than each tab content being an option. Maybe a select with the parameter set names, and depending on which parameter set you select from the dropdown, the parameter fields underneath it change?

Replied to the wrong one…

That makes sense to me. I agree tabs would make it seem like you need to fill out everything.

1 Like

The nice thing about this is the fact that parameter sets can be named anything, so we can give them a nice human-readable name to appear in the dropdown. So instead of just “id” it can be “Employee ID”, and instead of “since” it could be “Modified On or After” etc.

I realize now that this isn’t in the docs (getting it added now) but you can use the DisplayNameAttribute to set a display name for your parameters.

    [ComponentModel.DisplayName("My Script")]
1 Like

Hey @adam did this ever get any traction? Still love the idea of being able to specify which parameter set I want to populate when executing a script. Doesn’t seem to have made it into 2.7.0 unless I’m doing something wrong.

It didn’t get added yet. I actually didnt open an issue for it but now I did: Parameter Sets for Scripts · Issue #831 · ironmansoftware/issues · GitHub

1 Like