Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Advanced Function get current ParameterSetName

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).

like image 850
Eric Schoonover Avatar asked Apr 27 '10 04:04

Eric Schoonover


2 Answers

Use $PsCmdlet.ParameterSetName:

switch ($PsCmdlet.ParameterSetName) {
    "FromFile_ParamSet" {

    }
    "FromUri_ParamSet" {

    }
}
like image 100
Eric Schoonover Avatar answered Sep 29 '22 13:09

Eric Schoonover


As a way to expand this awesome answer:

switch ($PsCmdlet.ParameterSetName) {
    "FromFile_ParamSet" {
    }
    "FromUri_ParamSet" {
    }
    "__AllParameterSets" { 
    }
}

The __AllparameterSets is the default option in PS

like image 39
Jose Ortega Avatar answered Sep 29 '22 12:09

Jose Ortega