在選擇其他引數時,使用引數來強制使用引數
例如,如果要提供引數 User,則強制使用引數 Password。 (反之亦然)
Function Do-Something
{
Param
(
[Parameter(Mandatory=$true)]
[String]$SomeThingToDo,
[Parameter(ParameterSetName="Credentials", mandatory=$false)]
[String]$Computername = "LocalHost",
[Parameter(ParameterSetName="Credentials", mandatory=$true)]
[String]$User,
[Parameter(ParameterSetName="Credentials", mandatory=$true)]
[SecureString]$Password
)
#Do something
}
# This will not work he will ask for user and password
Do-Something -SomeThingToDo 'get-help about_Functions_Advanced' -ComputerName
# This will not work he will ask for password
Do-Something -SomeThingToDo 'get-help about_Functions_Advanced' -User