azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Can't delete Recovery Service Vault

Open ghost opened this issue 9 years ago • 9 comments

Cmdlet(s)

Remove-AzureRmRecoveryServicesVault

PowerShell Version

PSVersion 5.1.14409.1005

Module Version

OS Version

BuildVersion 10.0.14409.1005

Description

Can't delete RSVault01 using Remove-AzureRmRecoveryServicesVault -Vault 'RSVault01'

Debug Output

Remove-AzureRmRecoveryServicesVault : Cannot bind parameter 'Vault'. Cannot convert the "RSVault01" value of type "System.String" to type "Microsoft.Azure.Commands.RecoveryServices.ARSVault". At line:1 char:44

  • Remove-AzureRmRecoveryServicesVault -Vault 'RSVault01'
  •                                        ~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Remove-AzureRmRecoveryServicesVault], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.RecoveryServices.RemoveAzureRmRecoveryServicesVault

ghost avatar Jul 06 '17 04:07 ghost

@dragonfly91 would you mind taking a look at this issue? This seems like an important scenario we should be enabling

cormacpayne avatar Jul 07 '17 18:07 cormacpayne

PS C:\windows\system32> Remove-AzureRmRecoveryServicesVault

cmdlet Remove-AzureRmRecoveryServicesVault at command pipeline position 1 Supply values for the following parameters: Vault: RecoveryServicesVault Remove-AzureRmRecoveryServicesVault : Cannot bind parameter 'Vault'. Cannot convert the "RecoveryServicesVault" value of type "System.String" to type "Microsoft.Azure.Commands.RecoveryServices.ARSVault". At line:1 char:1

  • Remove-AzureRmRecoveryServicesVault
  •   + CategoryInfo          : InvalidArgument: (:) [Remove-AzureRmRecoveryServicesVault], ParameterBindingException
      + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.RecoveryServices.RemoveAzureRmRe
     coveryServicesVault
    

DanielGKnudsen avatar Sep 04 '17 10:09 DanielGKnudsen

@jahongirman , you need to pass Vault object to cmdlet Remove-AzureRmRecoveryServicesVault. You can use below cmdlet to get required vault object Get-AzureRmRecoveryServicesVault -ResourceGroupName -Name E.g.: $vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName rg01 -Name RSVault01 Remove-AzureRmRecoveryServicesVault -Vault $vault

pragrawa avatar Sep 07 '17 16:09 pragrawa

How can you close this thread? You didn't give a proper solution as well as have a terrible typo in your "solution" -->$vault = Get-**Get-**AzureRmRecoveryServicesVault

This still does not work:

Add-AzureRmAccount Select-AzureRmSubscription -SubscriptionName "XXXXXX" $vault = Get-AzureRmSiteRecoveryVault -ResourceGroupName XXXXXX -Name "XXXXXX" Remove-AzureRmSiteRecoveryVault -Vault $vault

Error: Remove-AzureRmSiteRecoveryVault : Cannot validate argument on parameter 'Vault'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:1 char:40

  • Remove-AzureRmSiteRecoveryVault -Vault $vault
  •                                    ~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Remove-AzureRmSiteRecoveryVault], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.SiteRecovery.RemoveAzureSiteRecoveryVault

johannfoot avatar Feb 28 '18 09:02 johannfoot

@johannfoot ,I have corrected the typo, thanks for reminding us. Regarding the command, command is Get-AzureRmRecoveryServicesVault, not Get-AzureRmSiteRecoveryVault. Similarly for Remove-AzureRmRecoveryServicesVault

For more information, please see documentation @ https://docs.microsoft.com/en-us/powershell/module/azurerm.recoveryservices/remove-azurermrecoveryservicesvault?view=azurermps-5.4.0

pragrawa avatar Feb 28 '18 17:02 pragrawa

@pragrawa Ah yes, that will work better, much appreciated. I do however still get failure which prompts me to ask if this will remove the vault even if there's still resources in it?

johannfoot avatar Mar 01 '18 09:03 johannfoot

@johannfoot I ran into this today.

Get-AzureRmRecoveryServicesVault -ResourceGroupName $ResourceGroupName -Name $VaultName | Remove-AzureRmRecoveryServicesVault

The error is not meaningful so I tried this: Get-AzureRmRecoveryServicesVault -ResourceGroupName $ResourceGroupName -Name $VaultName | Remove-AzureRmRecoveryServicesVault -Debug

Now I get this:

Vault cannot be deleted as there are existing resources within the vault. Please ensure there are no backup items, protected servers or backup management servers associated with this vault. Unregister the following containers associated with this vault before proceeding for deletion : MyServer. Unregister all containers from the vault and then retry to delete vault

I've removed the scheduled backup job using the 'generate PIN' and tried to delete the protected server but no joy. As the data is retained for 14 days I suspect I won't be able to delete the vault until after then?

Backups for this item have been recently deleted. Deleted backup data is retained for 14 days. After that time, it is permanently deleted.

I'm new to all this so could be talking rubbish!

gerguk avatar Sep 27 '18 11:09 gerguk

@gerguk You have to use Disable-AzureRmRecoveryServicesProtection on each protected item with -RemoveRecoveryPoints option. Please refer to this link.

dragonfly91 avatar Sep 27 '18 12:09 dragonfly91

Thanks @dragonfly91 I got it sorted in the end!

I had used this to create the Vault

$VaultName = 'test321'
$ResourceGroupName = 'Demo'
$Location = 'East US'
New-AzureRmRecoveryServicesVault -Name $VaultName -ResourceGroupName $ResourceGroupName -Location $Location

So used this to delete it

$MyVault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $ResourceGroupName -Name $VaultName
Set-AzureRmRecoveryServicesVaultContext -Vault $MyVault
$Cont = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "Windows" -BackupManagementType MARS -Name "myclient."
Unregister-AzureRmRecoveryServicesBackupContainer -Container $Cont
Get-AzureRmRecoveryServicesVault -ResourceGroupName $ResourceGroupName -Name $VaultName | Remove-AzureRmRecoveryServicesVault

gerguk avatar Sep 27 '18 15:09 gerguk