Which parameter set has been used?

PowershellParametersOptional Parameters

Powershell Problem Overview


I've used advanced parameter handling to support multiple parameter sets. Is there any pre-defined variable or way to determine which parameter set has been used to call the script?

e.g. something like

if($parameterSet -eq "set1") { ... } elseif ($parameterSet -eq "set2") { ... }

?

Powershell Solutions


Solution 1 - Powershell

Check the $PSCmdlet variable:

$PSCmdlet.ParameterSetName

Solution 2 - Powershell

You can check in your script:

$PsCmdlet.ParameterSetName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionD.R.View Question on Stackoverflow
Solution 1 - PowershellShay LevyView Answer on Stackoverflow
Solution 2 - PowershellCB.View Answer on Stackoverflow