Let's say I have a function like:
function Authenticate
{
param
(
[ValidateSet('WindowsAuthentication','UsernameAndPassword')]
[string]$AuthenticationType,
[Parameter(ParameterSetName='ParamSet1')]
[string]$Username,
[Parameter(ParameterSetName='ParamSet1')]
[string]$Password
)
..
}
And I would like to enforce these rules:
- Make the parameter set
ParamSet1
mandatory if$AuthenticationType = 'UsernameAndPassword'
- "Disable"
ParamSet1
entirely if$AuthenticationType = 'WindowsAuthentication'
It this possible?
Using the link from Tim Ferrill's answer, I created the following function to help create dynamic parameters:
And solved my particular problem in the following way:
It became unneeded to have a parameter set when using Dynamic Parameter so I removed the parameter set.