How to Set Up Hyper-V Replication on Windows Server 2012 R2
Hyper-V Replica is a built-in disaster recovery feature in Windows Server 2012 R2 that continuously replicates virtual machines from a primary Hyper-V host to a replica host over the network. In the event of a primary host failure, you can fail over to the replica, minimising downtime. This guide walks through configuring Hyper-V Replica on both the primary and replica servers, enabling replication for specific VMs, and testing failover.
Prerequisites
- Two Windows Server 2012 R2 hosts with the Hyper-V role installed
- Network connectivity between the primary and replica hosts
- Sufficient storage on the replica host to hold copies of replicated VMs
- DNS resolution or host file entries so both hosts can resolve each other by name
- Firewall rules permitting Hyper-V Replica traffic (port 80 for HTTP or 443 for HTTPS/certificate-based)
Step 1 — Configure the Replica Server
The replica server must be configured to accept replication traffic. Open Hyper-V Manager on the replica host, right-click the server name, and select Hyper-V Settings. Navigate to Replication Configuration and enable the server as a replica server.
Via PowerShell on the replica server:
Set-VMReplicationServer -ReplicationEnabled $true -AllowedAuthenticationType Kerberos -ReplicationAllowedFromAnyServer $true -DefaultStorageLocation "D:HyperV-Replicas"
For Kerberos authentication (domain-joined hosts), port 80 is used. For certificate-based authentication (cross-domain or workgroup), port 443 and a certificate thumbprint are required. To use certificate authentication:
Set-VMReplicationServer -ReplicationEnabled $true -AllowedAuthenticationType Certificate -CertificateThumbprint "ABCDEF1234567890" -ReplicationAllowedFromAnyServer $true -DefaultStorageLocation "D:HyperV-Replicas"
Step 2 — Configure Firewall Rules on the Replica Server
Hyper-V Replica uses specific firewall rules that must be enabled. Run on the replica server:
Enable-NetFirewallRule -DisplayName "Hyper-V Replica HTTP Listener (TCP-In)"
For HTTPS/certificate-based replication:
Enable-NetFirewallRule -DisplayName "Hyper-V Replica HTTPS Listener (TCP-In)"
Step 3 — Enable Replication on the Primary Server
On the primary Hyper-V host, enable replication for a specific VM. The VM must be in a running or stopped state (not saved or paused):
Enable-VMReplication -VMName "ProductionVM01" -ReplicaServerName "replica-host.domain.com" -ReplicaServerPort 80 -AuthenticationType Kerberos -CompressionEnabled $true -RecoveryHistory 5
Key parameters:
-RecoveryHistory: Number of additional recovery points to maintain (0 = latest only, up to 15 additional points)-CompressionEnabled: Compresses replication traffic to reduce bandwidth usage-ReplicaServerPort: Must match the port configured on the replica server
Step 4 — Perform the Initial Replication
After enabling replication, you must perform the initial replication to synchronise the VM state to the replica host. There are three methods:
Option A — Over the network (suitable for smaller VMs or high-bandwidth links):
Start-VMInitialReplication -VMName "ProductionVM01"
Option B — Using a seed (for large VMs or slow links, copy the VHD manually to the replica host first):
Start-VMInitialReplication -VMName "ProductionVM01" -UseBackup -InitialReplicationStartTime (Get-Date).AddHours(2)
Monitor initial replication progress:
Get-VMReplication -VMName "ProductionVM01" | Select-Object Name, State, Health, LastReplicationTime, PrimaryServerName, ReplicaServerName
Step 5 — Verify Replication Status
Once initial replication completes, ongoing replication occurs at the configured interval (default 5 minutes, configurable to 30 seconds or 15 minutes). Check status:
Measure-VMReplication -VMName "ProductionVM01"
View all VMs being replicated on the primary server:
Get-VMReplication | Select-Object VMName, State, Health, ReplicaServerName, LastReplicationTime | Format-Table -AutoSize
Replication health states are: Normal, Warning, or Critical. A Warning state may indicate replication lag or transient network issues. A Critical state requires investigation.
Step 6 — Configure Extended Replication (Optional)
Windows Server 2012 R2 supports extended replication — a third site that receives replication from the replica server (not the primary). This provides three-site DR capability:
Set-VMReplication -VMName "ProductionVM01" -ReplicaServerName "extended-replica.domain.com" -ReplicaServerPort 80 -AuthenticationType Kerberos -AsReplica $true
Step 7 — Test Failover
Test failover allows you to start a copy of the replicated VM on the replica host without affecting replication or the primary VM. This is the recommended way to validate your DR readiness:
# On the replica server:
Start-VMFailover -VMName "ProductionVM01" -AsTest
After testing, stop the test failover:
Stop-VMFailover -VMName "ProductionVM01"
Step 8 — Planned Failover
A planned failover is used for scheduled maintenance. The primary VM must be shut down first to ensure zero data loss:
# Shut down on primary:
Stop-VM -VMName "ProductionVM01"
# Initiate planned failover on primary:
Start-VMFailover -VMName "ProductionVM01" -Prepare
# Complete failover on replica server:
Start-VMFailover -VMName "ProductionVM01"
# Start the VM on the replica:
Start-VM -VMName "ProductionVM01"
Step 9 — Unplanned Failover
If the primary host fails unexpectedly, perform an unplanned failover on the replica server:
# On the replica server:
Start-VMFailover -VMName "ProductionVM01"
Start-VM -VMName "ProductionVM01"
After the primary is restored, you can reverse replication to replicate back from the (now primary) replica site:
Set-VMReplication -Reverse -VMName "ProductionVM01"
Start-VMInitialReplication -VMName "ProductionVM01"
Monitoring and Alerting
To set up basic monitoring for replication health via PowerShell, you can export status to a log:
Get-VMReplication | Where-Object { $_.Health -ne "Normal" } | Select-Object VMName, Health, State | Export-Csv -Path "C:LogsReplicationHealth.csv" -NoTypeInformation
Windows Server 2012 R2 also surfaces Hyper-V Replica events in Event Viewer under Applications and Services Logs > Microsoft > Windows > Hyper-V-VMMS.
Summary
Hyper-V Replica on Windows Server 2012 R2 provides an enterprise-grade, built-in disaster recovery solution at no additional software cost. By configuring the replica server to accept replication, enabling replication on individual VMs, and scheduling regular test failovers, you can maintain an up-to-date copy of your critical workloads on a secondary site. The combination of planned and unplanned failover capabilities, extended replication for three-site scenarios, and configurable recovery history makes Hyper-V Replica a practical DR tool for small and mid-size organisations running virtualised infrastructure.