When you want for example enforce the use of the parameter Password if the parameter User is provided. (and vise versa)
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