dcsimg
Read more on "Server OS Spotlight" »

Checking Hyper-V Replication Health Using PowerShell Cmdlets

By Nirmal Sharma (Send Email)
Posted November 12, 2013


Hyper-V Replica is a disaster recovery technology introduced with Windows Server 2012 (learn more about Hyper-V Replica in our earlier article on the subject), and the Hyper-V Manager is a handy tool to check the replication health status of all the virtual machines (VMs) currently running.

There are times, though, when you want to use the PowerShell cmdlets to check the replication health status. Server TutorialsFor example, in a large environment that hosts many Primary and Replica Servers, gathering the replication health status of all virtual machines using Hyper-V Manager can take a considerably long time.

There are more than 164 PowerShell cmdlets available for the Hyper-V Module on Windows Server 2012, and of these 16 are specifically designed for use with Hyper-V Replica. Of the 16 Hyper-V Replica PowerShell cmdlets, there are two PowerShell cmdlets you can use to check the Hyper-V Replication status and get the replication statistical data: Get-VMReplication and Measure-VMReplication.

PowerShell cmdlets not only allow you to check the replication health status of multiple virtual machines, they also provide low-level information on the replication health and then save the output in a CSV file. For example, you can get the last successful replication for all virtual machines and then save the output in a text or CSV file for further analysis. Similarly, you can access the names of all virtual machines that have a specific replication health status and that are currently replicating to a specific Replica Server in a table.

Both of these cmdlets show the replication health status but with the different information as shown in the below screenshot:

As you can see in the above screenshot, the Get-VMReplication cmdlet shows the replication health status of all the virtual machines on the current server (current server acting as the Primary Server) as well as the Replica Server name to which the virtual machines are replicating. It also displays the protocol and network port used to communicate with the Replica Server. Use the "Get-VMReplication" cmdlet if you need to get the replication health status of all virtual machines with the Replica Server name and its parameters.

On the other hand, the Measure-VMReplication cmdlet not only shows the replication health status of all the virtual machines, it also shows the last replication time (LReplTime) and average replication data size (AvgReplSize(m)), neither of which is shown in the "Get-VMReplication" cmdlet.

Both cmdlets implement two common properties that indicate the current replication health status and the state of the virtual machine. A virtual machine enabled for Hyper-V Replication can return one of three replication health statuses: "Normal," "Warning" or "Critical."

The replication health status is shown in the "Health" column in the output table. A replication state always indicates the current state of a virtual machine, which is reflected in the "State" column in the cmdlet output as shown in the above screenshot. Replication states of a virtual machine are explained shortly.

As explained earlier, a few properties are displayed by both the cmdlets, but some properties can only be found in one or the other cmdlet. For example, "Name," "State" and "Health" properties are displayed by both the Get-VMReplication and Measure-VMReplication cmdlets, but "FailedOverReplicationType," "LastTestFAiloverInitiatedTime" and many other properties are only implemented as part of the "Measure-VMReplication" cmdlet.

The properties implemented by both the cmdlets are shown in the below screenshots:

As you can see in the above screenshot, there are a few common properties in both cmdlets, but properties related to the replication health statistical data are implemented only in the Measure-VMReplication cmdlet. It is because the Get-VMReplication cmdlet offers information on Primary and Replica Server replication relationship whereas the Measure-VMReplicaitoncmdlet is used to get the replication health statistical data for a particular virtual machine.

In case of any issues with the replication or if you see "Critical" or "Warning" replication health status for any virtual machine, then use the Measure-VMReplication cmdlet to get the replication health statistical data.

Both the Get-VMReplication and Measure-VMReplication cmdlets support the -ComputerName parameter, which allows you to get the replication health data on a remote Hyper-V Server as shown in the below screenshot:

In addition to the -ComputerName parameter, both cmdlets support a number of other parameters as well. For example, if you only need to see a list of Primary virtual machines (the virtual machines that are replicating from Primary Server to Replica Server), you can use -ReplicationMode with "Primary" value as shown in the below screenshot:

A Primary Server can also act as a Replica Server replicating the virtual machines from another Primary Server, but this is not an ideal configuration in a production environment. In such a configuration, the "Mode" column will show "Primary" for Primary Virtual Machines and "Replica" for the Replica Virtual Machines.

Tip: It is imperative to understand the different modes a virtual machine can be in before you start troubleshooting problems. Since Hyper-V replication is one way (Primary Server replicates to Replica Server), the replication health status must always be obtained from the Primary Server to get more data for further troubleshooting.

Similar to -ReplicationMode, there is a -ReplicationState parameter that allows you to check for a specific replication state. For example, to get a list of all virtual machines that are not replicating or are in the "Error" replication state, you can use the below command:

As you can see in the above screenshot, the Get-VMReplication command only lists the virtual machines that are in the "Error" replication state. You can also specify the other replication states with the -ReplicationState parameter. A virtual machine can be in one of the below replication states:

  • Error: This replication state is shown if the virtual machine is not replicating anymore or is suffering from errors.
  • FailOverWaitingCompletion: This state indicates that the failover is still in progress.
  • FailedOver: This state indicates that the virtual machine failover is completed.
  • NotApplicable: The "NotApplicable" state is shown for a virtual machine that is not participating in the Hyper-V Replication.
  • ReadyForInitialReplication: This replication state is shown for the virtual machines for which Hyper-V replication is enabled but the initial replication has not been completed yet. This replication state is always shown on the Primary Server or for a Primary Virtual Machine.
  • Replicating: The virtual machine is replicating normally.
  • Resynchronizing: The resynchronization event has been triggered automatically or by an administrator.
  • ResynchronizeSuspended: The resynchronization process is paused.
  • Suspended: Virtual machine is suspended. In other words, the replication is paused.
  • SyncedReplicationComplete: Resynchronization has been completed successfully for the virtual machine.
  • WaitingForInitialReplication: This state is shown on the Replica Virtual Machine. This indicates that the replication is enabled for the virtual machine and a pointer has been created for the virtual machine at the Replica Server, but the initial replication has not been completed yet. On the Primary Server, the "ReadyForInitialReplication" replication state will be shown.
  • WaitingForStartResynchronize: A virtual machine may enter into this replication state if resynchronization needs to be done.

Tip: For any virtual machine participating in Hyper-V Replica, the "State" column should report a state of "Replicating" and the "Health" column should report "Normal."


Nirmal Sharma is a MCSEx3, MCITP and Microsoft MVP in Directory Services. He has specialized in Microsoft Technologies since 1994 and has followed the progression of Microsoft Operating System and software. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites and contributing to Solution IDs for www.Dynamic-SpotAction.com. Nirmal can be reached at nirmal_sharma@mvps.org.

Follow ServerWatch on Twitter and on Facebook

Page 1 of 1

Read more on "Server OS Spotlight" »

Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.