az cli: How to retrieve key vault secret value alone, with no double quotes?

24.7k Views Asked by At

Using az cli command of az keyvault secret show --name $SecretName --vault-name $KeyVaultName --query value) returns the secret with double quotes.

This causes my subsequent REST call to fail.

How do I return the secret value only, no double quotes?

I also tried the --outputs tsv flag, but this returns a bunch of values. Per the docs, the order is not guaranteed.

3

There are 3 best solutions below

0
On

@Gaurav Mantri thank you for your answer in the comment section converting it to answer

you can try this command to get the secret value without double quotes.

az keyvault secret show --name secretname --vault-name keyvaultname -o tsv

1
On

Friendly FYI: How to query Azure CLI command output using a JMESPath query has Bash, PowerShell and CMD examples to return values without quotes when using the Azure CLI.

0
On

This was the exact question I had and JayakrishnaGunnam-MT's answer was helpful.

I feel like putting it all together was the one missing piece that I needed.

So, the below statement is what gave me the exact result I needed--and I think is the most direct solution to the original question.

az keyvault secret show --name $SecretName --vault-name $KeyVaultName --query value -o tsv
  1. az keyvault secret show --name $SecretName --vault-name $KeyVaultName get the secret
  2. --query value query for only the value of the secret
  3. -o tsv format that query result to its raw value (no double quotes)

If I omit #2, I get more than just the secret value.

If I omit #3, I get just the secret value but with double quotes.

If I have that full statement, I get just the secret value and without double quotes--which is the result I need.