Reputation: 1973
I have a function with parameters like this:
param(
[string[]]$ComputerName,
[string]$exepath,
[string[]]$exeargs,
[switch]$help
)
If the User who uses this function uses the -help
switch, there must not be any other parameters declared to call the function. I want to prevent anyone using -help
alongside other parameters.
How can I achieve that? I read about_Functions_Advanced_Parameters but it doesn't really help me. I first thought what I need is a ValidateSet
but that's different from what I need.
Upvotes: 2
Views: 193
Reputation: 59031
You could use the ParameterSetName
attribute:
param(
[Parameter(ParameterSetName='default')]
[string[]]$ComputerName,
[Parameter(ParameterSetName='default')]
[string]$exepath,
[Parameter(ParameterSetName='default')]
[string[]]$exeargs,
[Parameter(ParameterSetName='help')]
[switch]$help
)
Upvotes: 2