I have a function worked out that has 2 parameter sets, both of which contain mandatory parameters. I would like to design the function so that the sets can each be used alone, or together. This is what I have put together:
function Do-This {
[CmdletBinding(DefaultParameterSetName='NoTransferOrCopy')]
Param(
[Parameter(ParameterSetName='CopyPermissions')]
[Parameter(ParameterSetName='CopyAndTransfer')]
[switch]$CopyPermissions,
[Parameter(ParameterSetName='CopyPermissions', Mandatory=$True)]
[Parameter(ParameterSetName='CopyAndTransfer', Mandatory=$True)]
[string]$FromUser,
[Parameter(ParameterSetName='CopyPermissions')]
[Parameter(ParameterSetName='CopyAndTransfer')]
[switch]$CopyAll,
[Parameter(ParameterSetName='TransferMDrive')]
[Parameter(ParameterSetName='CopyAndTransfer')]
[switch]$TransferMDrive,
[Parameter(ParameterSetName='TransferMDrive', Mandatory=$True)]
[Parameter(ParameterSetName='CopyAndTransfer', Mandatory=$True)]
[string]$OldServer,
[Parameter(ParameterSetName='TransferMDrive', Mandatory=$True)]
[Parameter(ParameterSetName='CopyAndTransfer', Mandatory=$True)]
[string]$NewServer
)
}
The only issue that I have is that for example, if I specify -CopyPermissions
by itself on the command line, I get an ambiguous parameter set message instead of being prompted for a value for FromUser
.
I understand why this is occurring, however if possible I would like to throw an error that is more descriptive, something like FromUser must be specified whenever CopyPermissions is set
. Is there any way I can do that?