将哈希表作为参数从 bash 传递到 pwsh
Passing hashtable as parameter from bash to pwsh
是否可以将哈希表作为 PowershellCore 中的变量作为 Bash 解释器的单行程序传递?
我正在尝试以下操作:
pwsh /path-to/script.ps1 -Param1 ABC -Param2 @{ "key"="value" }
在脚本中定义参数:
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$Param1,
[Parameter(Mandatory = $true)][hashtable]$Param2
)
...
收到错误消息:
script.ps1: Cannot process argument transformation on parameter
'Param2'. Cannot convert the "@{" value of type "System.String" to
type "System.Collections.Hashtable".
有没有办法将 Bash 中的哈希表传递给 Powershell?问题似乎出在 @{
值上。通常在 pwsh 中被原生接受。
谢谢
这是解决方案:
pwsh -c " /path-to/script.ps1 -Param1 ABC -Param2 @{ 'key'='value' } "
是否可以将哈希表作为 PowershellCore 中的变量作为 Bash 解释器的单行程序传递?
我正在尝试以下操作:
pwsh /path-to/script.ps1 -Param1 ABC -Param2 @{ "key"="value" }
在脚本中定义参数:
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$Param1,
[Parameter(Mandatory = $true)][hashtable]$Param2
)
...
收到错误消息:
script.ps1: Cannot process argument transformation on parameter 'Param2'. Cannot convert the "@{" value of type "System.String" to type "System.Collections.Hashtable".
有没有办法将 Bash 中的哈希表传递给 Powershell?问题似乎出在 @{
值上。通常在 pwsh 中被原生接受。
谢谢
这是解决方案:
pwsh -c " /path-to/script.ps1 -Param1 ABC -Param2 @{ 'key'='value' } "