Skip to content

Instantly share code, notes, and snippets.

@syedhassaanahmed
Last active December 3, 2021 09:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syedhassaanahmed/b423dd38af2f6b53a454fe0f8c06d843 to your computer and use it in GitHub Desktop.
Save syedhassaanahmed/b423dd38af2f6b53a454fe0f8c06d843 to your computer and use it in GitHub Desktop.
Copy secrets from one Azure Key Vault to another assuming they're both in the same Azure subscription
#!/bin/bash
set -euo pipefail
SOURCE_KV="<source_key_vault_name>"
DEST_KV="<destination_key_vault_name>"
SOURCE_SECRETS=$(az keyvault secret list --vault-name $SOURCE_KV --query "[].id" -o tsv | cut -d "/" -f5)
DEST_SECRETS=$(az keyvault secret list --vault-name $DEST_KV --query "[].id" -o tsv | cut -d "/" -f5)
MISSING_SECRETS=$(echo "${SOURCE_SECRETS} ${DEST_SECRETS}" | tr ' ' '\n' | sort | uniq -u)
for MISSING_SECRET in $MISSING_SECRETS
do
MISSING_VALUE=$(az keyvault secret show --vault-name $SOURCE_KV -n $MISSING_SECRET --query "value" -o tsv)
az keyvault secret set --vault-name $DEST_KV -n $MISSING_SECRET --value "$MISSING_VALUE"
done
@andyfaizan
Copy link

Thanks a ton!

@Makesh-Gmak
Copy link

Thanks a lot !!!

@francoran
Copy link

very helpful

@rahman6848
Copy link

Thanks a lot!

@algomes
Copy link

algomes commented Jul 9, 2021

man, you rocket it!!! thanks a lot

@taomoh
Copy link

taomoh commented Dec 3, 2021

Very helpful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment