13

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.

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
SeaDude
  • 3,725
  • 6
  • 31
  • 68
  • 2
    I am not able to reproduce the behavior. When I used `az keyvault secret show --name $SecretName --vault-name $KeyVaultName --query value -o tsv`, I only get the unquoted secret value. – Gaurav Mantri Sep 17 '21 at 14:25
  • There are many ways to solve this. @GauravMantri comment to add **-o tsv** is a simple/good solution. Another option is to use the tool **jq**. Output your data as JSON and process the desired keys. **jq** is what many developers use in command scripts. – John Hanley Sep 17 '21 at 19:47

3 Answers3

16

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.

egnomerator
  • 985
  • 8
  • 15
12

@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

JayakrishnaGunnam-MT
  • 1,548
  • 1
  • 5
  • 9
0

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.

  • Thanks for the answer - looks correct. However, in order to be immediately helpful to readers (and avoid link-rot), we prefer answers that provide at least a summary of the solution directly, with links used to offer additional information. – navicore Aug 04 '22 at 03:28