Parameter set to require one parameter when another is selected

suggest change

For 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'

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents