Parameter set to require one parameter when another is selected
suggest changeFor example, require Password when User is provided, and the other way around:
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
}
# Prompts for User and Password because -ComputerName selects the Credentials set.
Do-Something -SomeThingToDo 'get-help about_Functions_Advanced' -ComputerName 'localhost'
# Prompts for Password because -User selects the same set.
Do-Something -SomeThingToDo 'get-help about_Functions_Advanced' -User 'jane'
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents