Multiple parameter sets

How to implement it

[switch]$a,
[switch]$b,

[string]$c,

[string]$d,
[string]$e,

[string]$f

A C d E
B C d E
A C F
B C F
 

Not exactly sure of the question. Maybe if you provided some example code. In general though, take a look at the documentation in about_functions_advanced_parameters under the parametersetname argument. It looks to me like you have 4 parameters and parameter C would not have a parametersetname identified since it is in all three. For the parameters that appear in more than one parameter set, just include another parameter argument. Here is an example from the documentation previously referenced:

 

Param(
[Parameter(Mandatory=$true,
ParameterSetName="Computer")]
[String[]]
$ComputerName,

[Parameter(Mandatory=$true,
ParameterSetName="User")]
[String[]]
$UserName,

[Parameter(Mandatory=$false, ParameterSetName="Computer")]
[Parameter(Mandatory=$true, ParameterSetName="User")]
[Switch]
$Summary
)

[quote quote=201414]Not exactly sure of the question. Maybe if you provided some example code. In general though, take a look at the documentation in about_functions_advanced_parameters under the parametersetname argument. It looks to me like you have 4 parameters and parameter C would not have a parametersetname identified since it is in all three. For the parameters that appear in more than one parameter set, just include another parameter argument. Here is an example from the documentation previously referenced:

PowerShell
16 lines
<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 7.20125px; left: 52px; top: 0px;" spellcheck="false" wrap="off"></textarea>
<p style="text-align: left;">[/quote] I don't get any inspiration for this example</p>

Here’s another example. I think it is exactly what you are asking for.

function Inspiration {
Param(
[Parameter(ParameterSetName="Set1")]
[Parameter(ParameterSetName="Set3")]
[switch]
$A,

[Parameter(ParameterSetName="Set2")]
[Parameter(ParameterSetName="Set4")]
[switch]
$B,

[Parameter(ParameterSetName="Set1")]
[Parameter(ParameterSetName="Set2")]
[string]
$d,

[Parameter(ParameterSetName="Set1")]
[Parameter(ParameterSetName="Set2")]
[string]
$E,

[Parameter(ParameterSetName="Set3")]
[Parameter(ParameterSetName="Set4")]
[string]
$F,

[String]
$C
)

Switch ($PSCmdlet.ParameterSetName) {
"Set1" {"You are in parameter set 1"}
"Set2" {"You are in parameter set 2"}
"Set3" {"You are in parameter set 3"}
"Set4" {"You are in parameter set 4"}
}
}

Inspiration -A -C "Hello" -d "World" -E "It's me"
Inspiration -B -C "Hello" -d "World" -E "It's me"
Inspiration -A -C "Hello" -f "World"
Inspiration -B -C "Hello" -F "World"

 

You’re going to have to actually explain the problem you’re trying to solve, and show some of your actual code.

Good,I can’t understand how it works.