-1

I need a script or az command to move my secrets from keyvault01 to keyvault02.

Does someone have az commands for that scenario?

matthias_h
  • 11,356
  • 9
  • 22
  • 40
Anuj gupta
  • 19
  • 1
  • 8

1 Answers1

1

Do you already have another Key Vault, or just want to move one to a new resource group or subscription. You can do that in the portal:

enter image description here

If you just need to move a few secrets you can do something like this using the cross-platform Azure module for PowerShell:

Get-AzKeyVaultSecret -VaultName MyOldVaultName -Name test* `
  | foreach { Get-AzKeyVaultSecret -VaultName MyOldVaultName -Name $_.Name } `
  | foreach { `
    Set-AzKeyVaultSecret -VaultName MyNewVaultName `
      -Name $_.Name `
      -SecretValue $_.SecretValue `
      -Expires $_.Expires `
      -Disable:(!$_.Enabled) `
      -ContentType $_.ContentType `
      -Tag $_.Tags }

You need to call Get-AzKeyVaultSecret twice because listing secrets does not download the secret value, so a second call with the specific secret value you want is necessary to retrieve it.

Heath
  • 2,986
  • 18
  • 21