I want to make all parameters in a parameterset mandatory, but only if one of the parameters is actually specified (all or none situation).
So i want to be able to call my function as either Test-Mandatory -Param1
or Test-Mandatory -Param1 -Param2 -Param3
. So when i specify Param2, i want Param3 to be mandatory, and vice versa.
I would have thought that the something as the following would achieve this:
Function Test-Mandatory
{
Param
(
[switch]$Param1,
[Parameter(ParameterSetName='Set1', Mandatory)]
[switch]
$Param2,
[Parameter(ParameterSetName='Set1', Mandatory)]
[switch]
$Param3
)
}
However, when i use the above, i cannot call the function as Test-Mandatory -Param1
, as it will prompt me to provide a value for param2/param3.
I know i could add another parameter, add this to the set, and make it non mandatory, this would enable me to switch between the parametersets using the switch, but i would rather not do that.
Is there another way to solve this that i am overlooking?