I'm trying to work with the AZ CLI.
I need to create a certificate, and I'm having trouble with the JSON that needs to be passed into the Policy parameter. (I've been wrestling with string escapes and now an "unterminated string" that starts about halfway through the JSON)
The az keyvault certificate create
documentation has the following explanation for the --policy/-p
parameter:
JSON encoded policy definition. Use @{file} to load from a file(e.g. @my_policy.json).
I thought I would save my policy to a file (named .\policy.json
) and use it with the following syntax:
az keyvault certificate create --vault-name $kvDest `
-p @policy.json `
-n $cert.name;
However when I do this, I get an error that I can't use the splat operator like that.
The splatting operator '@' cannot be used to reference variables in an expression. '@policy' can be used only as an argument to a command. To reference variables in an expression use '$policy'.
Why can't I use @ to load the file like the documentation tells me that I can?
I'm using Powershell 5.1 on Window 10.
The documentation I'm referencing is here: https://learn.microsoft.com/en-us/cli/azure/keyvault/certificate?view=azure-cli-latest#az_keyvault_certificate_create
I've also found a blog post from 2018 where a guy demonstrates exactly what I'm trying to do and his syntax looks identical to mine here: https://techblog.hobor.hu/2018/08/26/self-signed-certificate-with-sans-using-azure-cli-keyvault/
I'm not sure if changing my PowerShell version is an option, so if the cause is that the syntax I'm trying to use is not available in Powershell 5.1, can you please help me find a fix for my unterminated string problem?