我正在尝试编写一个Powershell脚本,该脚本将一个字符串作为第一个参数,然后将可变数量的字典作为变量。
这是脚本的启动方式:
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $Identity,
[Parameter(Mandatory = $true,
ValueFromRemainingArguments=$true,
Position = 1)]
[ValidateNotNullOrEmpty()]
[hashtable[]] $Contacts
)
当我尝试如下执行脚本时:
。\ scriptName.ps1“ alice @ alice” @ {email =“ a”; firstName =“ fn”} @ {email =“ b”; firstName =“ fn2”}
我收到以下错误:
D:\ Griffin \ sources \ dev \ SubstrateSearch \ src \ TdsDeployment \ SetupSubstrateSearchServices \ Scripts \ CreateExplicitContacts.ps1 :无法在参数“联系人”上处理参数转换。 无法转换价值 键入“ System.Collections.Generic.List`1 [System.Object]” “ System.Collections.Hashtable []”。错误:“无法转换 类型为“ System.String”的“ alice @ alice”值键入 “ System.Collections.Hashtable”。“在第1行:char:1 +。\ CreateExplicitContacts.ps1“ alice @ alice” @ {email =“ a”; firstName =“ f ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidData:(:) [CreateExplicitContacts.ps1], ParameterBindingArgumentTransformationException + FullyQualifiedErrorId:ParameterArgumentTransformationError,CreateExplicitContacts.ps1
我在做什么错了?