I have a function that have this parameters:
param (
[Parameter (Mandatory = $false,
ParameterSetName = "SendMail",
HelpMessage = "Call this parameter to send information mail ONLY.")]
[switch]$SendMail,
[Parameter (Mandatory = $false,
Position = 0,
ParameterSetName = "UseRegion",
HelpMessage = "Call this parameter to use the function with Regions.")]
[Parameter (Mandatory = $false,
ParameterSetName = "UseCountry")]
[switch]$UseRegions,
[Parameter (Mandatory = $false,
ParameterSetName = "SendMail")]
[Parameter (Mandatory = $true,
ParameterSetName = "UseRegion",
HelpMessage = "Define the region to apply the function.")]
[ValidateSet("AMER","APAC","EMEA")]
[string]$Region,
[Parameter (Mandatory = $false,
ParameterSetName = "SendMail")]
[Parameter (Mandatory = $false,
ParameterSetName = "UseRegion")]
[Parameter (Mandatory = $true,
HelpMessage = "Define the country to apply the function.",
ParameterSetName = "UseCountry")]
[ValidateNotNullOrEmpty()]
[string]$Country,
[Parameter (Mandatory = $false,
HelpMessage = "Define months for a machine to be outdated. Default value is 3.")]
[ValidateRange(1, [int]::MaxValue)]
[int]$Months = 3,
[Parameter (Mandatory = $false,
HelpMessage = "Define days for a machine to be on the ""Disabled"" OU before permanent deletion. Minimum and default value is 7.")]
[ValidateRange([int] 7, [int] 30)]
[int]$DaysToDeletion = 7,
[Parameter (Mandatory = $false,
HelpMessage = "Define operation to exclude from the rule. I.E.: Operations that does not connect to the VPN.")]
[string]$Exclude
)
i'm trying to acomplish the following:
When i call -SendMail NO parameter is mandatory When i call -UseRegions, -Region is mandatory and the rest is not. When i don't call -UseRegions, -Country is mandatory and the rest is not.
I've been playing with parameter sets but i can never get it to resolve. I also don't want to have an extra parameter called -UseCountry, i want -UseRegions to controll both -Region and -Country.
Anyone had anything like it?
Thanks a lot in advance!!!!
I get it, parameter sets make even my head spin sometimes. What it sounds like, is that you want 3 different sets.
You can remove all but the
-SendMail
switch by usingmandatory = $true
.Now if you do a
help potato
the SYNTAX section will show this