0

I am trying to add a certificate to an Azure Key Vault using Azure CLI. I'm following the documentation here and the quickstart here. Both pages say the command to generate a certificate is:

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

I have this exact line in my script:

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

I get the following exception every time I run it. Am I missing something obvious here?

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

Connell.O'Donnell
  • 3,603
  • 11
  • 27
  • 61

1 Answers1

1

It is because Powershell saves the output of get-default-policy in a different encoding from that of bash and CMD.

Please use this workaround:

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

az keyvault certificate create --vault-name $keyVault -n $certName --policy `@defaultpolicy.json
Allen Wu
  • 15,529
  • 1
  • 9
  • 20