I am trying to create a new Azure Key Vault secret using the Azure Cli v2.9.0 (we use this version in our pipelines and upgrading would be difficult at the moment.) via the command below,
az keyvault secret set --vault-name $myKeyVaultName -n $mySecretName --value "abc^def"
The command is accepted and a new secret is created but it drops the caret (^) from the string and results in a secret value of abcdef instead of the intended abc^def.
During my testing I have seen the below message from Powershell but it's very rare : Unable to encode the output with cp1252 encoding. Unsupported characters are discarded.
Strange as tjhe caret is in the character set - https://en.wikipedia.org/wiki/Windows-1252#Code_page_layout
Is there a way to run this command and get Key Vault to accept the value with the caret?
I can reproduce your issue.
Actually, it depends on your environment, this issue just occurs when you run the command in Powershell
, if you run the CLI command in Bash
, it works fine.
az keyvault secret set --vault-name joykeyvault -n testkey12 --value "abc^def"
So if you want to run this command in Powershell
environment, just use the line below.
az keyvault secret set --vault-name joykeyvault -n testkey12 --value '"abc^def"'
Thanks Joy that works. Just out of interest how do you form the --value option if the string is in a variable such as --value @myValue?
@PhilMurray In powershell environment? If so, I don't think the variable way will work, not 100% sure,I recommend you to post a new question.
Thank you. I have raised a separate question.