I am writing a function in PowerShell 3.0 . One parameter in the function should be set as mandatory depending on the value of another parameter.
The function declaratioin would be as following:
function removeVolumeandArrayFromHost(){
Param( [Parameter(mandatory = $true)] [ValidateSet('iSCSI','FC')] $arrayType, ##IpAddress/Name of the target host
[Parameter(mandatory = $true)] $volumeName, ##Name of the volume to be disconnected. (Volume name as in the array.)
[Parameter(mandatory = $false)] $FCACL, ##Access control list name to which volume is added (Related to FC Array only)
## Work with the parameters given.
}
In the above function, The parameter '$arrayType' can have the value 'iSCSI' or 'FC'.
The parameter $FCACL should be mandatory(mandatory = $true) only if $arrayTpe = 'FC'. if $arrayType = 'iSCSI' then the $FCACL parameter should not be mandatory (mandatory = $false)
I tried using parametersetname but it dosent help as I need to lookinto the value of the parameter $arrayType to decide if $FCACL would be mandatory or not.
Any type of help or pointers would be highly appreciated.
Thanks a lot in advance. :)