Recovery Vault not being deleted due to hang around VM

Risto LavettAzureKommentera

recovery vault

I came accross an interesting error in an customer environment the other day when configuring a Recovery Vault in Azure. The Azure Backup Recovery vault is the built in backup/restore service that Azure provides for Virtual Machines. Sometimes you delete VM’s and also delete the complete Recovery Vault to move it somewhere else.

Problem:

This is what I did, I deleted the VM’s (since they were temporary test servers) and then removed them from the Recovery Vault. All worked fine. Although when I wanted to delete the Recovery Vault itself it gave me an error, even if i tried from powershell, portal and all kinds of different ways. Somehow one of the VM’s “hang around” in the Recovery Vault although I couldn’t see it when i listed resources in the Recovery Vault.

There was no data in the vault, no servers, no nothing.

The error I got was this (from powershell using the AzureRM powershell module):

PS C:\> get-azurermrecoveryservicesvault -ResourceGroupName MYRESOURCEGROUP

Name : MYRECOVERYVAULT
ID : /subscriptions/MYSUBSCRIPTIONID/resourceGroups/ MYRESOURCEGROUP/providers/Microsoft.RecoveryServices/vaults/ MYRECOVERYVAULT
Type : Microsoft.RecoveryServices/vaults
Location : northeurope
ResourceGroupName : MYRESOURCEGROUP
SubscriptionId : MYSUBSCRIPTIONID
Properties : Microsoft.Azure.Commands.RecoveryServices.ARSVaultProperties

 
PS C:\> $vault=(get-azurermrecoveryservicesvault -ResourceGroupName MYRESOURCEGROUP)

PS C:\> Remove-AzureRmRecoveryServicesVault -Vault $vault

 
Remove-AzureRmRecoveryServicesVault : Operation Failed.
ErrorCode: ServiceResourceNotEmpty
Message: Vault cannot be deleted as there are existing resources within the vault.
Please delete any registered servers, Hyper-V sites (Used for Site Recovery), policy associations for SCVMM clouds (Used for Site Recovery) and then delete the vault.
At line:1 char:1
+ Remove-AzureRmRecoveryServicesVault -Vault $vault
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureRmRecoveryServicesVault], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.RemoveAzureRmRecoveryServicesVault

Also when using the Armclient.exe I got the same error:

 “error”: {“code”: “ServiceResourceNotEmpty”,”message”: “Vault cannot be deleted as there are existing resources within the vault.\nPlease delete any registered servers, Hyper-V sites (Used for Site Recovery), policy associations for SCVMM clouds (Used for Site Recovery) and then delete the vault.”,”target”: null,”details”: null,”innerError”: null}

Solution:

After som investigation I manage to solve the problem by doing the following:

  • Get the ARMClient from https://chocolatey.org/packages/ARMClient
  • Login using subscription credential with the command (using cmd prompt): ARMClient.exe login
  • Unregister the hang around VM using following command:

ARMClient.exe delete /subscriptions/ SUBSCRIPTIONNAME/resourceGroups/ RESOURCEGROUP/providers/Microsoft.RecoveryServices/vaults/ RECOVERYVAULTNAME/registeredIdentities/VMNAMEFQDN?api-version=2016-06-01

  • Then delete the Recovery Vault from the portal or powershell.

Good Luck and be careful so you delete the right resources!, it took me some while to figure this solution out 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *