Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Deleting an Azure Recovery Services Vault with all Backup Items

When I am prototyping Azure solutions with Azure Resource Manager templates and scripts, I often find myself allocating resources and when I am done, I will delete the entire resource group to clean up. If you have ever created some backups in Azure Recovery Services Vault you will know that you cannot simply remove the Azure Recovery Services vault without removing any backup items that you have in there. The details on how to do that can be found here. It is however a bit painful to click your way through deleting a lot of backup items, so I use a PowerShell script. It looks something like this:

First make sure you login:



Login-AzureRmAccount -Environment AzureUSGovernment

if you are using Azure Government

Then create a script, e.g. DeleteRecoveryServicesVault.ps1:



$rv = Get-AzureRmRecoveryServicesVault -Name $VaultName -ResourceGroupName $ResourceGroupName
Set-AzureRmRecoveryServicesVaultContext -Vault $rv
$rcs = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVM

foreach ($c in $rcs) {
    $bi = Get-AzureRmRecoveryServicesBackupItem -Container $c -WorkloadType AzureVM
    Disable-AzureRmRecoveryServicesBackupProtection -Item $bi -RemoveRecoveryPoints -Force

Remove-AzureRmRecoveryServicesVault -Vault $rv

And you can remove the vault with:

.DeleteRecoveryServicesVault.ps1 -ResourceGroupName  -VaultName 

Of course, you may need to make adjustments depending on what types of workloads you have in the vault. Keep the script handy for when you need to do that again.

Be careful. This script will wipe out your recovery services vault. Make sure that is what you want to do.

Share the post

Deleting an Azure Recovery Services Vault with all Backup Items


Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription