How to set parameter as mandatory if choice ? selected from validateset?

I have the following parameter input and three choices the user can type:

Param(
    [Parameter(Mandatory=$true)]
    [ValidateSet('View','Add','Remove')]
    [String]$Command,

    [Parameter(Mandatory=$false)]
    [String]$UserID
)

How can I make it so that it’s mandatory to enter $UserID if $Command is either “Add” or “Remove”, while not mandatory if “View” is the command?

I know there is dynamic parameters…but if there is an easier way to do this its even better :slight_smile:

otherwise, how would i do it with dynamicparam?

When you crosspost could you please at least place links to the other crossposts. That would provide some help for the helpers and avoid getting the same advises more than once!

Click: StackOverflow

[quote quote=144156]When you crosspost could you please at least place links to the other crossposts. That would provide some help for the helpers and avoid getting the same advises more than once!

Click: StackOverflow

[/quote]
yep. i was testing the script first to see if its working and then was planning to either post answer here or link :slight_smile:

I meant you should play fair and post a link to the other crossposts at first. :-/ … and that’s valid for this forum as well as for the others.