Home > Blockchain >  AZ CLI loop to download
AZ CLI loop to download

Time:08-05

I am looking for a method to loops through using specifically az cli, in order to download for example secrets/keys. I already have an ideea of what I am trying to achieve, but I would like to do it through az cli and I can't seem to understand how to loops through, like a for loop to go through all the keys/secrets and download them locally. is there a way ? any sort of example would be useful. It must be in az cli.

CodePudding user response:

Using Powershell or Bash you could always list all the secrets in a vault, iterate and backup.

Here is a Powershell sample:

$keyVaultName = "<key vault name>"

# list secrets in a vault
$secrets = az keyvault secret list `
  --vault-name $keyVaultName `
| ConvertFrom-Json

foreach ($secret in $secrets) {
  # backup each secret
  $filename = "$($secret.name).txt"
  az keyvault secret backup `
    --vault-name $keyVaultName `
    --name $secret.name `
    --file $filename
}
  • Related