Force Disable of Azure Replication from Orphaned On Premise Hyper-V Virtual Machine.

After successfully stopping and removing protection for one of my replica virtual machines in Azure Site Recovery, I observed that the on premise primary virtual machine replication status changed to a failed state. This would be normal behavior considering that replication settings at the Azure target had been removed.


My attempts at disabling replication at the primary VM via the GUI failed. I encountered the following error shown in the screen shot below trying to remove it using the PowerShell cmdlet: Remove-VMReplication -VMName w81:


Please note that I had initially setup Hyper-V (non-SCVMM) to Azure VM replication. The on premise Hyper-V host seemed to believe that the VM replication is still being managed by Azure. After doing some research, I found a four line code on the Microsoft Azure website under the section “Clean up protection settings manually (between Hyper-V sites and Azure)” , that utilizes the WMI Object.

$vmName = "SQLVM1"
$vm = Get-WmiObject -Namespace "root\virtualization\v2" -Query "Select * From Msvm_ComputerSystem Where ElementName = '$vmName'"
$replicationService = Get-WmiObject -Namespace "root\virtualization\v2" -Query "Select * From Msvm_ReplicationService"

I downloaded and saved the script as a PowerShell function (Remove-OrphanedVMReplication.ps1) after replacing the "SQLVM1" string with the name of my virtual machine. I ran the script in a PowerShell console as Administrator and it successfully disabled replication at the primary on premise VM.


After further research, I will add that Azure Site Recovery has two options for removing a replicated item from Azure:

1) Disable Protection for the Machine (Recommended). As stated in the screen shot, this option will remove the machine and it will no longer be protected by ASR. Protection configuration and settings will be automatically cleaned up. Leaving the on premise Primary VM in a clean replication state.


2) Stop Managing the Machine. Also, as shown, this option removes the replica VM and it will no longer be available in ASR. The Protection settings for the Primary on premise VM will be unaffected, leaving the administrator with the clean up task as described with the script above. I had used this option to remove the replica VM above. This left the on premise VM in the state that required a manual clean up.


This entry was posted in Azure, Azure Site Recovery, Azure VPN and tagged , , , , , , , , , , , . Bookmark the permalink.

6 Responses to Force Disable of Azure Replication from Orphaned On Premise Hyper-V Virtual Machine.

  1. jespernohr2015 says:

    Thank You !

  2. Kahl says:

    That worked great to remove the server but now I am not able to add it back in under site recovery. It is the only server missing on the list. Any thought on how to get it back? Thanks!

    • Kahl says:

      I found that I still had the remnants of the of the replicated server in Azure. Once I cleaned them all out it worked. This was really straightforward. I would prefer if you removed my comments, Thanks!

  3. Andy says:

    Very nice, it worked!

  4. Erwin C says:

    Worked for me. I probably picked stop because my on-premisse VM was left in a critical state for months.
    You don’t need to save the commands in a script. You can past them one by one in Powershell.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s