Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Mandatory only in a specific parameterset

$
0
0

You can decorate the parameters like this

function test {
 
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$Param1,
 
[Parameter(Mandatory)]
[string]$Param2,
 
[Parameter(ParameterSetName = 'Set1')]
[switch]$Param3,
 
[Parameter(ParameterSetName = 'Set1',Mandatory)]
[Parameter(ParameterSetName = 'Set2')]
[string]$Param4,
 
[Parameter(ParameterSetName = 'Set2')]
[string]$param5
)
 
 
}

£> test -Param1 xx -Param2 yy -Param3
cmdlet test at command pipeline position 1
Supply values for the following parameters:
Param4:

£> test -Param1 x -Param2 y -param5 z


Viewing all articles
Browse latest Browse all 13067

Trending Articles