我有一个具有以下参数的函数:
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
)
我正在尝试完成以下操作:
当我调用 -SendMail 时,NO 参数是强制性的 当我调用 -UseRegions 时,-Region 是强制性的,其余的不是。当我不调用 -UseRegions 时,-Country 是强制性的,其余的则不是。
我一直在玩参数集,但我永远无法解决它。我也不想有一个名为-UseCountry 的额外参数,我想要-UseRegions 来控制-Region 和-Country。
有人有过类似的吗?
非常感谢提前!!!!