The tasks and their parameter sets are:. All is good as long as one of the parameters is specified but if we try to run the command either without specifying any parameter we will get an error stating:. If you choose to do one of these ways, you can not use the others, so they all must be in different ParameterSetName groups. For parameters that belong to multiple parameter sets, add a Parameter attribute for each parameter set. Related 3. As I developed my function, I found that I wanted to support various use cases, which presently are as follows:. This easiest way is to call Get-Command with the parameter —Syntax like this:. To make it more clear which parameter has which value, the function now also prints the value of each parameter. Office Office Exchange Server.
A colleague asked the question of whether a parameter function could belong to multiple parameter sets, but not all of them, say in Set A and B. Sometimes you need to add more than one parameter set to a function you're creating. If that's not something you're familiar with, it can be a. If you want a fast sanity check on your parameter sets, you can use Show-Command.
This will display a form with multiple tabs, one for each parameter set.
Sign up using Email and Password. I also want the Path parameter to be available when using either of the parameter sets.
Cmdlet Parameter Sets PowerShell Microsoft Docs
I have a function worked out that has 2 parameter sets, both of which contain mandatory parameters. Which reminds me, I've been meaning to get in touch with Yucca Mountain to see if they're interested in a partnership.
Video: Multiple parameter sets powershell Windows PowerShell - How to - Defining Parameters
If you choose to do one of these ways, you can not use the others, so they all must be in different ParameterSetName groups.
Meaning, you can only have.
Hot Network Questions. Return the latest x number of comics -newest. Multiple parameter sets In the following illustration, the left column shows three valid parameter sets.
Adding Multiple Parameter Sets to a PowerShell Function – Mike F Robbins
For example, you can define a parameter as mandatory in one set and optional in another. Get-Command still shows the parameter Name as being named and not Positional! So, just like with the first set, if you choose one thing, you can not choose any of the others in these groups. The following example explicitly adds the Summary parameter to the Computer and User parameter sets.