Estoy tratando de eliminar todos los backup items de un recovery service vault usando powershell. He encontrado un script pero este script elimina item por item esperando a que el primero se termine de eliminar para pasar al siguiente. Me gustaría modificar el script para, por ejemplo, ordenarle a Azure que elimine el item y pase al siguiente mientras el anterior se está eliminando. Intenté usar el flag -AsJob pero powershell no lo reconoce (lo tengo comentado en el código). Estoy usando la versión 5 de powershell. Tengo que eliminar cientos o miles de backup items por lo que ir uno a uno no es una opción.
¿Podrían ayudarme?
## Variables
$rgBackup = Read-Host -Prompt "Introduce el nombre del resource group"
$vaultName = Read-Host -Prompt "Introduce el nombre del recovery service vault"
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $rgBackup -Name $vaultName
$count = 0
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Disable soft delete for the Azure Backup Recovery Services vault
Set-AzRecoveryServicesVaultProperty -Vault $vault.ID -SoftDeleteFeatureState Disable
Write-Host ($writeEmptyLine + " # Soft delete disabled for Recovery Service vault " + $vault.Name)`
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Check if there are backup items in a soft-deleted state and reverse the delete operation
$containerSoftDelete = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureWorkload -WorkloadType MSSQL -VaultId $vault.ID | Where-Object {$_.DeleteState -eq "ToBeDeleted"}
foreach ($item in $containerSoftDelete) {
Undo-AzRecoveryServicesBackupItemDeletion -Item $item -VaultId $vault.ID -Force -Verbose
}
Write-Host ($writeEmptyLine + "# Undeleted all backup items in a soft deleted state in Recovery Services vault " + $vault.Name)
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Stop protection and delete data for all backup-protected items
$containerBackup = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $vault.ID | Where-Object {$_.DeleteState -eq "NotDeleted"}
foreach ($item in $containerBackup) {
Disable-AzRecoveryServicesBackupProtection -Item $item -VaultId $vault.ID -RemoveRecoveryPoints -Force -Verbose #-AsJob
$count++
Write-Host "$count - Item has been deleted"
}
Write-Host ($writeEmptyLine + "# Deleted backup date for all cloud protected items in Recovery Services vault " + $vault.Name)`