我有一个带有相当长参数集的 powershell 脚本:
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
)
我已经根据我的需要测试了这些参数的功能,它工作正常,除了在一种特殊情况下:当我使用参数 SharedElement、OnlyListing 和 Reference 运行脚本时
script.ps1 -SharedElement email.address@domain.com -OnlyListing -Reference "Some string"
我总是得到一个错误:
无法使用指定的命名参数解析参数集
但是,当我使用参数 SharedElement、OnlyListing 和 NoLog 运行脚本时,它可以正常工作:
script.ps1 -SharedElement email.address@domain.com -OnlyListing -NoLog
几个月来我一直想知道问题可能是什么,但我一直无法找到解决方案。谁能指出帮助我解决问题的提示?
非常感谢您提前。问候。