Search code examples
powershellpowershell-cmdlet

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


Solution

  • As a way to expand this awesome answer:

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

    The __AllparameterSets is the default option in PS