问题描述
是否可以通过Bash解释器将哈希表作为变量作为PowershellCore中的变量传递?
我正在尝试:
pwsh /path-to/script.ps1 -Param1 ABC -Param2 @{ "key"="value" }
在脚本中具有已定义的参数
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$Param1,[Parameter(Mandatory = $true)][hashtable]$Param2
)
...
收到错误消息:
script.ps1:无法处理参数的参数转换 'Param2'。无法将类型“ System.String”的“ @ {”值转换为 键入“ System.Collections.Hashtable”。
有什么方法可以将Bash中的哈希表传递给Powershell吗? @{
值似乎有问题。通常在本地接受的pwsh中。
谢谢
解决方法
这是解决方案:
pwsh -c " /path-to/script.ps1 -Param1 ABC -Param2 @{ 'key'='value' } "