Created
July 3, 2024 23:05
-
-
Save Wind010/d2f9d93b4bb7566f9d098360fda4d4f3 to your computer and use it in GitHub Desktop.
List KeyVault secrets with Azure CLI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory=$true)] | |
[string]$KeyVaultName, | |
[Parameter(Mandatory=$true)] | |
[string]$SubscriptionName | |
) | |
az account set -s "$SubscriptionName" | |
$secrets = az keyvault secret list --vault-name "$KeyVaultName" --query '[].{Name:name, Version:version}' --output tsv | |
$secrets_array = $secrets -split "`n" | |
foreach ($line in $secrets_array) { | |
$secret_name = ($line -split "\t")[0] | |
$secret_version = ($line -split "\t")[1] | |
# Debug with --debug flag. | |
$secret_value = az keyvault secret show --name "$secret_name" --vault-name "$KeyVaultName" --query value -o tsv | |
Write-Host "Secret Name: $secret_name" | |
Write-Host "Secret Value: $secret_value" | |
Write-Host "" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <keyvault-name> <subscription-name>" | |
exit 1 | |
fi | |
KEY_VAULT_NAME=$1 | |
SUBSCRIPTION_NAME=$2 | |
az account set -s $SUBSCRIPTION_NAME | |
SECRETS=$(az keyvault secret list --vault-name "$KEY_VAULT_NAME" --query '[].{Name:name, Version:version}' --output tsv) | |
while IFS=$'\t' read -r name version; do | |
SECRET_VALUE=$(az keyvault secret show --name "$name" --vault-name "$KEY_VAULT_NAME" --query value -o tsv) | |
#az keyvault secret show --name "$name" --vault-name "$KEY_VAULT_NAME" --query value -o tsv --debug | |
echo "Secret Name: $name" | |
echo "Secret Value: $SECRET_VALUE" | |
echo "" | |
done <<< "$SECRETS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment