Pergunta

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

Foi útil?

Solução

As a way to expand this awesome answer:

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

The __AllparameterSets is the default option in PS

Outras dicas

Use $PsCmdlet.ParameterSetName:

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

    }
    "FromUri_ParamSet" {

    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top