powershell - 接受可变数量的哈希集作为参数
问题描述
我正在尝试编写一个 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”类型。” 在 line:1 char:1 + .\CreateExplicitContacts.ps1 "alice@alice" @{email="a"; firstName="f ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [CreateExplicitContacts.ps1], ParameterBindingArgumentTransformationException + FullyQualifiedErrorId :
我究竟做错了什么?
解决方案
推荐阅读
- c# - xml 在 Datagrid 中翻译列名
- .net - ArcGIS UWP 离线地图
- asp.net-mvc-4 - 如何将图标添加到标题栏
- aem - 如何在 AEM RTE 中使用多个自定义插件?
- jquery - 如何将类添加到jquery中当前单击的元素?
- selenium - 当找到第一个匹配项时,如何退出在@findbyall 的定位器策略下查找元素?
- nginx - Nginx lua 日志位置
- css - 从外部更改阴影 dom 中的文本颜色
- python - 有没有办法根据孩子的透视变换自动将透视变换应用于父级?
- java - 如何使用 springboot-data-couchbase 配置多个 couchbase 数据源?