How to delete a failed backup item in Recovery Services Vault programmatically (Powershell 7.2)
Lo Presti-Costantino Massimo, I251
0
Reputation points
I am trying, via Automation Account Runbook, to remove everything in a Recovery Service Vault to be able to delete it.
I have a Backup Item in failed state, the storage account with the file share is already deleted.
I need, via Powershell, to be able to undelete it, like I would do it via Portal.
I downloaded the code to remove the Recovery Services Vault directly from portal
# Using Az.RecoveryServices module version 7.3.0
$vault = Get-AzRecoveryServicesVault
# Disable soft delete
Set-AzRecoveryServicesVaultProperty -VaultId $vault.Id -SoftDeleteFeatureState "Disable"
Write-Output "Soft delete disabled for the vault"
# Disable Security features (Enhanced Security) to remove MARS/MAB/DPM servers.
Set-AzRecoveryServicesVaultProperty -VaultId $vault.id -DisableHybridBackupSecurityFeature $true
Write-Output "Disabled Security features for the vault"
$backupItemsAFS = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureStorage -WorkloadType AzureFiles -VaultId $vault.Id
foreach ($item in $backupItemsAFS)
{
Undo-AzRecoveryServicesBackupItemDeletion -Item $item -VaultId $vault.Id -Force
# If I try this get the error ->
# Undo-deletion is only supported for AzureVMs. This method is not supported for other workloads.
Disable-AzRecoveryServicesBackupProtection -Item $item -VaultId $vault.Id -RemoveRecoveryPoints -Force
# This will raise the error ->
# Container is not yet undeleted. Please undelete the container that contains this datasource before attempting to undelete the datasource.
}
Am I missing something ?
Thanks for helping ;-)
Sign in to answer