I have a function with the following parameter requirements:
- There are no required parameters
$Credential
can optionally be used with any other parameters, or no other parameters$Title
,$Username
, and$SearchString
cannot be used together$DefaultObject
and$AsPlainText
can only be used with$Title
or$Username
$DefaultObject
and$AsPlainText
cannot be used together
Below is what I have so far:
[CmdletBinding(DefaultParameterSetName = 'All')]
param (
[PSCredential] $Credential,
[Parameter(ParameterSetName = 'Title')]
[string] $Title,
[Parameter(ParameterSetName = 'Username')]
[string] $Username,
[Parameter(ParameterSetName = 'Search')]
[string] $SearchString,
[Parameter(ParameterSetName = 'Title')]
[Parameter(ParameterSetName = 'Username')]
[Parameter(ParameterSetName = 'DefaultObject')]
[switch] $DefaultObject,
[Parameter(ParameterSetName = 'Title')]
[Parameter(ParameterSetName = 'Username')]
[Parameter(ParameterSetName = 'PlainText')]
[switch] $AsPlainText
)
I have accomplished items 1-4 on the list, but I am struggling with item 5 to prevent $DefaultObject
and $AsPlainText
from being called simultaneously. Does anybody know how to prevent them from being used together? I have already tried creating a new ParameterSet for each of them, but that did not work.