# Get keyvault tokencurl "$IDENTITY_ENDPOINT?resource=https://vault.azure.net&api-version=2017-09-01"-H secret:$IDENTITY_HEADER# Connect with PS AzureAD## $token from management APIConnect-AzAccount -AccessToken $token -AccountId 1937ea5938eb-10eb-a365-10abede52387 -KeyVaultAccessToken $keyvaulttoken
# List vaultsGet-AzKeyVault# Get secrets names from the vaultGet-AzKeyVaultSecret-VaultName <vault_name># Get secret valuesGet-AzKeyVaultSecret-VaultName <vault_name>-Name <secret_name> –AsPlainText
#!/bin/bash# Dump all keyvaults from the subscription# Define Azure subscription IDAZ_SUBSCRIPTION_ID="your-subscription-id"# Specify the filename for outputCSV_OUTPUT="vault-names-list.csv"# Login to Azure accountazlogin# Select the desired subscriptionazaccountset--subscription $AZ_SUBSCRIPTION_ID# Retrieve all resource groups within the subscriptionAZ_RESOURCE_GROUPS=$(azgrouplist--query"[].name"-otsv)# Initialize the CSV file with headersecho"Vault Name,Associated Resource Group"> $CSV_OUTPUT# Iterate over each resource groupfor GROUP in $AZ_RESOURCE_GROUPSdo# Fetch key vaults within the current resource groupVAULT_LIST=$(azkeyvaultlist--resource-group $GROUP --query"[].name"-otsv)# Process each key vaultfor VAULT in $VAULT_LISTdo# Extract the key vault's nameVAULT_NAME=$(azkeyvaultshow--name $VAULT --resource-group $GROUP --query"name"-otsv)# Append the key vault name and its resource group to the fileecho"$VAULT_NAME,$GROUP">> $CSV_OUTPUTdonedone