In this Azure Article, we will discuss how to fix the error, ” Vault Cannot Be Deleted As There Are Existing Resources Within The Vault “. This error I got when I was trying to delete one of the Recovery Services vaults. Along with this, we will also discuss the below topics
- How to delete azure recovery services vault
- How to delete azure recovery services vault using PowerShell
Table of Contents
Vault Cannot Be Deleted As There Are Existing Resources Within The Vault
Recently, I was trying to clear the unused Azure resources to reduce the cost, When I tried to delete one of the Azure Recovery Services vaults, it didn’t allow me to delete and I got the error “Vault cannot be deleted as there are existing resources within the vault“
- You are not eligible for an Azure subscription
- The following commands are already available on this system
The completely error message was as below
Vault cannot be deleted as there are existing resources within the vault: Please ensure all containers have been unregistered from the vault and all private endpoints associated with the vault have been deleted, and retry the operation. For more details, see https://aka.ms/AB-AA4ecq5
I followed the below steps to delete the Azure Recovery Service vault. My Azure Recovery Service vault name was vault938 that I was trying to delete.
How to delete azure recovery services vault
Navigate to the Recovery Services vault, click on the Recovery Services vault that you want to delete. On the Recovery Services vault page, click on the Delete button.
Then I clicked on the Yes button for the confirmation
I got the below Vault deletion error as “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault” as shown below.
Now the reason I got this error is that there is a Backup item for the Azure Virtual Machine that is attached to this Recovery Services vault. To check that, click on the Backup items link under Protected items on the Recovery Services vault page.
After clicking on the Backup items, you can see for the Azure Virtual Machine, the Backup Item count is 1. Click on the Azure Virtual Machine.
You can see below, this the Virtual Machine backup instance that is attached to the Azure Recovery Services vault.
Now to fix this error, what you need to do is, you need to delete the Backup Items(Azure Virtual Machine).
To delete this, select the Azure Virtual Machine back up instance, click on the three dots (…) or you can right-click on that for the same options and then click on the stop backup option.
Now click on the Stop Backup button to confirm the Stop Backup functionality.
Now you can see the Stopping backup functionality completed successfully.
Now after stopping the backup, select the Azure Virtual Machine back up instance, click on the three dots (…) or you can right-click on that for the same options and then click on the Delete backup data option
Type the name of the Backup item and then click on the Delete button to delete the Backup data.
Note: An important thing to note here is the name of the Backup Item is case sensitive and you need to enter exactly the same name of the Backup Data as it is.
You can see below it deleted the backup data for the virtual machine successfully.
See here, The restore points for this backup item have been deleted and retained in the soft delete state and will be available for 13 more days to recover. After which they will be permanently deleted. That means even though you deleted the Backup data but it is available still for 13 more days in soft delete state then after it will delete permanently.
You can see below the Backup items (Azure Virtual Machine) is in Soft delete state.
Now again if you will try to delete the Azure Recovery Services vault, it will not allow you to delete and you will get the below error
Recovery Services vault cannot be deleted as there are backup items in the soft-deleted state in the vault. The soft-deleted items are permanently deleted after 14 days of the delete operation. Please try vault deletion after the backup items are permanently deleted and there is no item in the soft-deleted state left in the vault. For more information, refer
Vault Cannot Be Deleted As There Are Existing Resources Within The Vault [Solution]
So now you have two options to delete the Azure Recovery Services vault to fix the error “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault”
Option-1: You need to wait for the 14 days and then after it will completely delete the soft delete backup data automatically, after that, you can try deleting the Azure Recovery Services vault, it will allow you to delete this time without any issue.
Option-2: If you want to permanently delete the soft delete data immediately instead of waiting for the 14 days, then you need to follow the below steps to do that. Then after you can able to delete Azure Recovery Services vault immediately without any issue.
The first step is to disable the Soft delete option in the Azure Portal, to do that. Click on the Properties under settings option on the Recovery Services vault page and then click on the Security Settings —> Update link.
On the Security Settings page, Select the Disabled button for the Soft Delete (For Azure Virtual Machines) option and then click on the Save button to update the changes.
As mentioned below, you can see once you disabled the Soft delete option, all future deletes will be immediate and will not have soft delete protection.
Now the settings is updated.
Now the Soft Delete (For Azure Virtual Machines) option is disabled so now on the next step, select the Soft delete backup data and click on the three dots (…), click on the Undelete option.
Click on the Undelete button to confirm the undelete functionality.
Now if you will try deleting the backup data, you can able to delete the backup data with out any issue.
Just to verify, you can see below, the backup data is deleted successfully.
Since there is no backup data present for the Azure Virtual Machine, so now if you try deleting the Azure Recovery Services vault, you can able to delete it without any issue.
Click on the Yes button to confirm the Deletion process
You can see below the Recovery Services vault successfully deleted with out any issue.
Just to reconfirm you can see below there is no Recovery services vault present.
This is how we can fix the error “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault” and This is how we can delete azure recovery services vault using the Azure Portal.
How to delete azure recovery services vault using PowerShell
We discussed above How to delete azure recovery services vault using Azure Portal. Now let’s discuss How to delete azure recovery services vault using PowerShell.
You can use below PowerShell cmdlet to identify the items that are in soft-deleted state
Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $myOldVaultID | Where-Object {$_.DeleteState -eq "ToBeDeleted"}
$newItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $myOldVaultID -Name MyNewVM
Now you need to reverse the deletion operation that was performed when the soft-delete was enabled using the below PowerShell cmdlet
Undo-AzRecoveryServicesBackupItemDeletion -Item $newItem -VaultId $myOldVaultID -Force
Soft-delete is now disabled, now use the below PowerShell cmdlet for the deletion operation
Disable-AzRecoveryServicesBackupProtection -Item $newItem -RemoveRecoveryPoints -VaultId $myOldVaultID -Force
This is how we can delete Azure recovery services vault using PowerShell as discussed above.
You may also like going through the below tutorials
- Azure Active Directory Module for Windows Powershell
- Microsoft Azure Backup Agent
- No match was found for the specified search criteria and module name ‘AzureRM’
- Method ‘get_serializationsettings’ in type ‘microsoft.azure.management
- The term ‘connect-azaccount’ is not recognized as the name of a cmdlet
Conclusion
Well, in this tutorial, we discussed how to fix the error “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault”. Along with this we also discussed How to delete Azure recovery services vault using the Azure Portal and finally, we discussed, How to delete Azure recovery services vault using PowerShell.