0
votes

I have to restore all blob files to the same key vault from where i backed up the files. I have backed up the files using the referenced website. Then deleted all the secrets and now 'restore all' is not working.I can restore individual secrets but not all of them at once.

I am trying following script.

[string]$VaultName = 'NewVault' 
Get-AzureKeyVaultSecret -VaultName $VaultName | ForEach-Object { 

Restore-AzureKeyVaultSecret -VaultName $VaultName -InputFile ('C:\Backup1\backup_{0}.blob' -f $_."Name") 

}

Reference

Azure Key Vault: Backup Secrets using PowerShell

1
the script from the link you've shared is doing the opposite: backup secrets from key vault .Thiago Custodio
It is not restoring to the same key vault, it runs and does not give any error and then completes. Restoration of individual secret is working fineAtif Khalid
You are correct, i took the reference from the link, backed up all secrets, then tried restore by changing some values. Now need help as it is not working.Atif Khalid
it's still not clear what you have. You're changing locally and want to send to key vault the updated version? You've changed in the key vault and wants to override the previous version locally? Please be more specific and edit your questionThiago Custodio
updated my questionAtif Khalid

1 Answers

0
votes

If you want to restore all secrets in a folder to keyvault, you could use the script below.

[string]$VaultName = 'joykeyvault'
$files = Get-ChildItem C:\Backup1 -Filter Backup_*.blob -Recurse | % { $_.FullName }
foreach($file in $files){
   Restore-AzureKeyVaultSecret -VaultName $VaultName -InputFile $file  
}

Note: In the screenshot, I use the new Az command Restore-AzKeyVaultSecret, in your case, you are using the old AzureRM module, so just use Restore-AzureKeyVaultSecret.

enter image description here