In C# you can get the current ParameterSetName in the ProcessRecord override of a PowerShell Cmdlet with code like this:
switch (ParameterSetName)
{
case FromUriParamSetName:
loadFromUri();
break;
case FromFileParamSetName:
loadFromFile();
break;
}
I'm trying to figure out how I can get the value for ParameterSetName in a script cmdlet (Advanced Function).
Use $PsCmdlet.ParameterSetName:
switch ($PsCmdlet.ParameterSetName) {
"FromFile_ParamSet" {
}
"FromUri_ParamSet" {
}
}
As a way to expand this awesome answer:
switch ($PsCmdlet.ParameterSetName) {
"FromFile_ParamSet" {
}
"FromUri_ParamSet" {
}
"__AllParameterSets" {
}
}
The __AllparameterSets is the default option in PS
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