Q
Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

What PowerShell commands are used to configure Hyper-V replication?

Use these simple PowerShell commands to enable Hyper-V Replica, to initiate replication for a specific VM and to obtain the replication status for that VM.

Hyper-V Replica helps in achieving availability of VMs. You keep virtual workloads running on Hyper-V hosts in...

the production site and replicate the same workloads to Hyper-V hosts running in disaster recovery sites. If any disaster strikes at the production site, virtual workloads at disaster recovery sites will be brought online to provide services. While you can enable Hyper-V Replica using Hyper-V Manager or System Center Virtual Machine Manager, I find it more quick and efficient to use PowerShell. Here are the PowerShell commands you need to run in order to manage Hyper-V replication.

Note that you will need at least two Hyper-V hosts running Windows Server 2012 or later in order to configure Hyper-V replication. Hyper-V hosts running in a production site will be known as primary servers and Hyper-V hosts in a disaster recovery site will be known as replica servers.

First, run the command shown below on the replica server in order to enable Hyper-V Replica:

Enable-Netfirewallrule -DisplayName "Hyper-V Replica HTTP Listener (TCP-In)" Set-VMReplicationServer -ReplicationEnabled $true “-AllowedAuthenticationType Kerberos” -KerberosAuthenticationPort 10000 “-DefaultStorageLocation "D:\ReplicatedVMs" “ -ReplicationAllowedFromAnyServer $true

This command configures Hyper-V replication on the replica server and also enables required firewall rules to accept replication from the primary server.

Next, execute the following command on the primary server to enable Hyper-V replication for a particular VM:

Enable-VMReplication -VMName "SQLVM" ` -ReplicaServerName "ReplicaServer.TechTarget.Com" ` -ReplicaServerPort 10000 -AuthenticationType Kerberos ` -CompressionEnabled $true -RecoveryHistory 5

This command enables replication for a VM named SQLVM. The VM is configured to replicate its contents with the replica server. Note that, as part of the command, we are also enabling compression and the recovery history is set to 5.

Finally, you will be required to initiate the replication of SQLVM, so the contents are replicated to the replica server, as shown in the command below:

Start-VMInitialReplication –VMName SQLVM

Once the contents of SQLVM are replicated to the replica server, SQLVM at the replica server will be turned off and SQLVM at the primary server will be running to provide required services. To get the replication status for SQLVM, what you can do is execute Measure-VMReplication on the primary server as shown in the following command:

Measure-VMReplication SQLVM

Next Steps

Speed up the Hyper-V replication process

Learn about Windows Server 2016 Storage Replica

Decide between Hyper-V replication and Storage Replica

This was last published in March 2017

Dig Deeper on Microsoft Hyper-V management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What other PowerShell commands help with Hyper-V replication?
Cancel

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close