Powershell 如何将选项作为地图传递?

Powershell 如何将选项作为地图传递?,powershell,hashicorp-vault,powershell-core,Powershell,Hashicorp Vault,Powershell Core,我遇到了这个bash脚本,我需要在PowerShell中做同样的事情 vault write ssh-client-signer/roles/my-role -<<"EOH" { "allow_user_certificates": true, "allowed_users": "*", "default_extensions": [ { "p

我遇到了这个bash脚本,我需要在PowerShell中做同样的事情

vault write ssh-client-signer/roles/my-role -<<"EOH"
{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}
EOH
但是该命令没有正确解析该选项

Failed to parse K=V data: invalid key/value pair "-@\n{\n  allow_user_certificates: true,\n  allowed_users: *,\n  default_extensions: [\n    {\n      permit-pty: \n": format must be key=value

我找到了一种使用PowerShell运行命令的方法,方法是要求
vault
读取JSON文件中的选项

vault write ssh/roles/my-role "@my-role.json";

但这并没有回答最初的问题。

这是echoargs的输出。这样看来是行不通的

echoargs -@"
{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}
"@


Arg 0 is <-@
{
  allow_user_certificates: true,
  allowed_users: *,
  default_extensions: [
    {
      permit-pty:
>
Arg 1 is <}
>
Arg 2 is <],
>
Arg 3 is <key_type:>
Arg 4 is <ca,
>
Arg 5 is <default_user:>
Arg 6 is <ubuntu,
>
Arg 7 is <ttl:>
Arg 8 is <30m0s
}
@>
echoargs-@”
{
“允许用户证书”:true,
“允许的用户”:“*”,
“默认_扩展”:[
{
“许可证私人股本”:
}
],
“密钥类型”:“ca”,
“默认用户”:“ubuntu”,
“ttl”:“30毫秒”
}
"@
arg0是
arg1是
arg2是
arg3是
arg4是
arg5是
arg6是
arg7是
arg8是
如果你想度过难关,你可能不得不把所有的引号反斜杠。如果您无法将json传输到它

$myarg = @"
{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}
"@ -replace '"','\"'


echoargs -$myarg

Arg 0 is <-{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}>
$myarg=@”
{
“允许用户证书”:true,
“允许的用户”:“*”,
“默认_扩展”:[
{
“许可证私人股本”:
}
],
“密钥类型”:“ca”,
“默认用户”:“ubuntu”,
“ttl”:“30毫秒”
}
“@-替换“”,”\“'
echoargs-$myarg
arg0是

这是echoargs的输出。这样看来是行不通的

echoargs -@"
{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}
"@


Arg 0 is <-@
{
  allow_user_certificates: true,
  allowed_users: *,
  default_extensions: [
    {
      permit-pty:
>
Arg 1 is <}
>
Arg 2 is <],
>
Arg 3 is <key_type:>
Arg 4 is <ca,
>
Arg 5 is <default_user:>
Arg 6 is <ubuntu,
>
Arg 7 is <ttl:>
Arg 8 is <30m0s
}
@>
echoargs-@”
{
“允许用户证书”:true,
“允许的用户”:“*”,
“默认_扩展”:[
{
“许可证私人股本”:
}
],
“密钥类型”:“ca”,
“默认用户”:“ubuntu”,
“ttl”:“30毫秒”
}
"@
arg0是
arg1是
arg2是
arg3是
arg4是
arg5是
arg6是
arg7是
arg8是
如果你想度过难关,你可能不得不把所有的引号反斜杠。如果您无法将json传输到它

$myarg = @"
{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}
"@ -replace '"','\"'


echoargs -$myarg

Arg 0 is <-{
  "allow_user_certificates": true,
  "allowed_users": "*",
  "default_extensions": [
    {
      "permit-pty": ""
    }
  ],
  "key_type": "ca",
  "default_user": "ubuntu",
  "ttl": "30m0s"
}>
$myarg=@”
{
“允许用户证书”:true,
“允许的用户”:“*”,
“默认_扩展”:[
{
“许可证私人股本”:
}
],
“密钥类型”:“ca”,
“默认用户”:“ubuntu”,
“ttl”:“30毫秒”
}
“@-替换“”,”\“'
echoargs-$myarg
arg0是

您误解了Bash示例的工作原理,实际执行的命令是

vault写入ssh客户端签名者/角色/我的角色-

如果
-
是从stdin读取值,而
您误解了Bash示例的工作方式,那么实际执行的命令是

vault写入ssh客户端签名者/角色/我的角色-

其中,
-
将从stdin读取值,
您是否尝试将此处字符串管道传输到
vault
<代码>@'…'@|&vault编写ssh客户端签名者/角色/我的角色-
您能详细解释一下“没有正确解析选项”是什么意思吗?您遇到了什么错误?我编辑了帖子以添加错误您是否尝试将此处字符串管道传输到
vault
<代码>@'…'@|&vault编写ssh客户端签名者/角色/我的角色-
您能详细解释一下“没有正确解析选项”是什么意思吗?你得到了什么错误?我编辑了帖子以添加错误