I wrote a function with four parameters. The first two parameters are mandatory for both sets : Payload
and Algorithm
.
The last two parameters (Secret
and FilePath
) define the parameter set.
The order of defined paramters is:
- Payload
- Algorithm
- Secret
- FilePath
I set Payload
the positional value of 0 and Algorithm
the value of 1.
As Secret
and FilePath
are mutually exclusive I set their value to 2.
[<Parameter(
Position=0,
Mandatory=true,
ValueFromPipelineByPropertyName=true)>]
[<ValidateNotNullOrEmpty>]
member val Payload : Hashtable = Hashtable () with get, set
[<Parameter(
Position=1,
Mandatory=true,
ValueFromPipelineByPropertyName=true)>]
member val Algorithm : cryptographyType = { Algorithm = HMAC; Encryption = SHA256 } with get, set
[<Parameter(
Position=2,
ParameterSetName="Key",
Mandatory=true,
ValueFromPipelineByPropertyName=true)>]
[<ValidateNotNullOrEmpty>]
member val Secret : string = String.Empty with get, set
[<Parameter(
Position=2,
ParameterSetName="FilePath",
Mandatory=true,
ValueFromPipelineByPropertyName=true)>]
[<ValidateNotNullOrEmpty>]
member val FilePath : System.IO.FileInfo = null with get, set
When I run the function using only the positions, I get a file error when I intend to use the FilePath
parameter because the function probably expects it to be the Secret
parameter.
Is there a way to use positional parameter for parameter sets?
If you want the
FilePath
parameter set to be the default, set theDefaultParameterSetName
property on aCmdlet
attribute decorator on the containing type: