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") { ... }
?
Parameter sets enable you to expose different parameters to the user. And, to return different information based on the parameters specified by the user. You can only use one parameter set at a time.
As illustrated here, the Get-Process cmdlet has three different parameter sets.
The CmdletBinding attribute is an attribute of functions that makes them operate like compiled cmdlets written in C#. It provides access to the features of cmdlets. PowerShell binds the parameters of functions that have the CmdletBinding attribute in the same way that it binds the parameters of compiled cmdlets.
The PowerShell parameter is a fundamental component of any script. A parameter is a way that developers enable script users to provide input at runtime. If a PowerShell script's behavior needs to change in some way, a parameter provides an opportunity to do so without changing the underlying code.
Check the $PSCmdlet variable:
$PSCmdlet.ParameterSetName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With