在 Azure CLI 中创建密钥保管库证书时出错

Error creating key vault certificate in Azure CLI

我正在尝试使用 Azure CLI 将证书添加到 Azure Key Vault。我正在关注文档 here and the quickstart here。两个页面都说生成证书的命令是:

az keyvault certificate create --vault-name vaultname -n cert1 -p "$(az keyvault certificate get-default-policy)"

我的脚本中有这样一行:

az keyvault certificate create --vault-name $keyVault -n $certName -p "$(az keyvault certificate get-default-policy)"

每次 运行 我都会得到以下异常。我在这里遗漏了什么明显的东西吗?

az : Expecting property name enclosed in double quotes: line 1 column 5 (char 4)

这是因为 Powershell 以不同于 bash 和 CMD 的编码保存 get-default-policy 的输出。

请使用此解决方法:

az keyvault certificate get-default-policy | Out-File -Encoding utf8 defaultpolicy.json

az keyvault certificate create --vault-name $keyVault -n $certName --policy `@defaultpolicy.json