I'm trying to disable the Azure Site Recovery Protection from Azure VMs through Azure Powershell (Az Module). The idea is to get the VM using the name and Resource Group:
Get-AzVM -Name $name -ResourceGroupName $rgName
And then disable the protection using any linking data that connects the VM to the ASR Protected Item.
As per my understanding, this can be done using the following cmdlet:
Remove-AzRecoveryServicesAsrReplicationProtectedItem
This cmdlet requires a Replication Protected Item Object:
Get-AzRecoveryServicesAsrReplicationProtectedItem
Which requires a Protection Container, which in turn requires a Fabric, which, lastly, requires the Vault.
Of course, I can get these parameters and objects if I know them beforehand. But that would defeat the purpose of creating a script that resolves them programmatically by using the Azure Virtual Machine name and RG.
I can't find any way of linking or getting this information from the Azure VM object...
I had to resolve a somewhat similar situation with Backups, and I achieved it using:
Get-AzRecoveryServicesBackupStatus -Name $vmname -ResourceGroupName $rg -Type "AzureVM"
$container = (Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -VaultId $VaultID | where-object {$_.FriendlyName -eq $vmname -and $_.ResourceGroupName -eq $rg})
But I can't find any cmdlet similar to that one which would take the VM Object or at least the VM name and RG name as parameters...
- Can this be done?
- How does the Portal links the VM and the ASR Item when you select Disaster Recovery from the VM Dashboard?