I have a powershell script with rather long parameter sets:
Param(
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Senders')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Recipients')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Global')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Manager')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'CatalogueName')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'OnlyListing')]
[String]$SharedElement,
[Parameter(Mandatory = $true, ParameterSetName = 'Senders')]
[String]$Senders,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $true, ParameterSetName = 'Recipients')]
[String]$Recipients,
[Parameter(Mandatory = $true, ParameterSetName = 'Global')]
[String]$Global,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $true, ParameterSetName = 'Manager')]
[Alias("Owner")]
[String]$Manager,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $true, ParameterSetName = 'CatalogueName')]
[String]$CatalogueName,
[Parameter(Mandatory = $true, ParameterSetName = 'ReapplyPermissions')]
[Switch]$ReapplyPermissions,
[Parameter(Mandatory = $true, ParameterSetName = 'OnlyListing')]
[Switch]$OnlyListing,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $false, ParameterSetName = 'CatalogueName')]
[Parameter(Mandatory = $false, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Mandatory = $false, ParameterSetName = 'OnlyListing')]
[Switch]$NoLog,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $false, ParameterSetName = 'CatalogueName')]
[Parameter(Mandatory = $false, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Mandatory = $false, ParameterSetName = 'OnlyListing')]
[String]$Reference,
[Parameter(Mandatory = $false, ParameterSetName = 'Senders')]
[Parameter(Mandatory = $false, ParameterSetName = 'Recipients')]
[Parameter(Mandatory = $false, ParameterSetName = 'Global')]
[Parameter(Mandatory = $false, ParameterSetName = 'Manager')]
[Parameter(Mandatory = $false, ParameterSetName = 'CatalogueName')]
[Parameter(Mandatory = $false, ParameterSetName = 'ReapplyPermissions')]
[Parameter(Mandatory = $false, ParameterSetName = 'OnlyListing')]
[Switch]$AskCredentials,
[Parameter(Mandatory = $true, ParameterSetName = 'Help')]
[Switch]$Help
)
I have tested the functionality of these parameters according to my needs and it works fine except in one particular case: when I run the script with parameters SharedElement, OnlyListing and Reference
script.ps1 -SharedElement [email protected] -OnlyListing -Reference "Some string"
I always get an error:
Parameter set cannot be resolved using the specified named parameters
However when I run the script with parameters SharedElement, OnlyListing and NoLog it works fine:
script.ps1 -SharedElement [email protected] -OnlyListing -NoLog
I have been wondering for months what the problem could be and I haven't been able to find a solution. Can anyone point a hint to help me to resolve the problem?
Thank you very much in advance. Regards.
After the first comment I copied the code from this web page, pasted it into my script and it worked fine. I compared the script with the previous version in my SVN repository and there was a difference in the parameter set name "OnlyListing" applied to the $Reference parameter. Apparently both parameter set names were identical but one of them contained a hidden character.
Thank you everybody for the help.