Skip to content

Instantly share code, notes, and snippets.

@pritpalp
Last active May 2, 2023 10:14
Show Gist options
  • Save pritpalp/b25caf70c9b83fd088434fdee83c5703 to your computer and use it in GitHub Desktop.
Save pritpalp/b25caf70c9b83fd088434fdee83c5703 to your computer and use it in GitHub Desktop.
Bard response to copying secrets and renaming them from one keyvault to another

Sure, here are the steps on how to copy secrets from one keyvault to another, renaming the secrets:

  1. Sign in to the Azure portal.
  2. Go to the Key Vaults blade.
  3. Select the source key vault.
  4. Click the Secrets tab.
  5. Select the secrets that you want to copy.
  6. Click the Copy button.
  7. In the Copy Secret dialog box, specify the following:
    • Destination Key Vault: The name of the destination key vault.
    • New Secret Names: The new names for the secrets.
    • Tags: Any tags that you want to associate with the secrets.
  8. Click the Copy button.

The secrets will be copied to the destination key vault with the new names.

Here is an example of a Bash script that you can use to copy secrets from one keyvault to another, renaming the secrets:

#!/bin/bash

# Get the source and destination keyvault names
source_keyvault_name=$1
destination_keyvault_name=$2

# Get a list of the secrets in the source keyvault
secrets=$(az keyvault secret list --vault-name $source_keyvault_name)

# Iterate over the secrets
for secret in $secrets; do

    # Get the secret name and value
    secret_name=$(echo $secret | cut -d' ' -f1)
    secret_value=$(echo $secret | cut -d' ' -f2)

    # Create a new secret in the destination keyvault with the new name
    az keyvault secret create --vault-name $destination_keyvault_name \
        --name $secret_name \
        --value $secret_value
done

This script will copy all of the secrets from the source keyvault to the destination keyvault, renaming the secrets with the new names that are specified in the script.

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