How to Configure Hyper-V Replica for Disaster Recovery on Windows Server 2012 R2
Hyper-V Replica is an asynchronous virtual machine replication feature built into Windows Server 2012 R2 Hyper-V. It continuously replicates virtual machines from a primary site to a replica site over HTTP or HTTPS, enabling rapid failover when the primary site experiences an outage. Unlike traditional DR solutions, Hyper-V Replica requires no shared storage, no SAN infrastructure, and no expensive third-party software — it uses built-in Windows features to achieve RPOs as low as 30 seconds (with Extended Replication) and RTOs measured in minutes. This guide covers a complete Hyper-V Replica deployment including initial configuration, failover testing, and monitoring.
Prerequisites
– Two Windows Server 2012 R2 Hyper-V hosts (Primary and Replica)
– Network connectivity between both hosts (LAN or WAN)
– Sufficient storage on the Replica host for replicated VMs
– For HTTPS: SSL certificates on both hosts
– For cluster-based deployment: Windows Server 2012 R2 Failover Cluster on each site
– PowerShell with Hyper-V module available
– Firewall rules allowing replication traffic (port 80 for HTTP, 443 for HTTPS)
Step 1: Configure the Replica Server
The Replica server must be configured to accept incoming replication connections before you can enable replication on the primary:
# On the REPLICA HOST (dr-hv01.dr.corp.local)
Import-Module Hyper-V
# Enable Hyper-V Replica with HTTP (lab/trusted network)
Set-VMReplicationServer `
-ReplicationEnabled $true `
-AllowedAuthenticationType Kerberos `
-ReplicationAllowedFromAnyServer $false `
-DefaultStorageLocation "D:HyperVReplica"
# Configure firewall rule for Hyper-V Replica (HTTP port 80)
Enable-NetFirewallRule -Name "VIRT-HVRHTTPL-In-TCP-NoScope"
# Enable Replica with HTTPS and certificate authentication (production recommended)
$replCert = Get-ChildItem Cert:LocalMachineMy |
Where-Object { $_.Subject -like "*dr-hv01*" } | Select-Object -First 1
Set-VMReplicationServer `
-ReplicationEnabled $true `
-AllowedAuthenticationType Certificate `
-CertificateThumbprint $replCert.Thumbprint `
-ReplicationAllowedFromAnyServer $false `
-DefaultStorageLocation "D:HyperVReplica"
# Enable HTTPS firewall rule
Enable-NetFirewallRule -Name "VIRT-HVRHTTPS-In-TCP-NoScope"
# Authorize specific primary hosts (restrict which hosts can replicate to this server)
New-VMReplicationAuthorizationEntry `
-AllowedPrimaryServer "prod-hv01.corp.local" `
-ReplicaStorageLocation "D:HyperVReplicaprod-hv01" `
-TrustGroup "ProductionSite"
New-VMReplicationAuthorizationEntry `
-AllowedPrimaryServer "prod-hv02.corp.local" `
-ReplicaStorageLocation "D:HyperVReplicaprod-hv02" `
-TrustGroup "ProductionSite"
# Verify configuration
Get-VMReplicationServer | Format-List *
Get-VMReplicationAuthorizationEntry | Format-Table AllowedPrimaryServer, ReplicaStorageLocation
Step 2: Enable Replication for Virtual Machines
# On the PRIMARY HOST (prod-hv01.corp.local)
Import-Module Hyper-V
# View VMs available for replication
Get-VM | Select-Object Name, State, Status | Format-Table -AutoSize
# Enable replication for a single VM with Kerberos (HTTP)
Enable-VMReplication `
-VMName "WebServer01" `
-ReplicaServerName "dr-hv01.dr.corp.local" `
-ReplicaServerPort 80 `
-AuthenticationType Kerberos `
-CompressionEnabled $true `
-ReplicaPath "D:HyperVReplicaprod-hv01WebServer01"
# Enable replication with HTTPS/Certificate
$replCert = Get-ChildItem Cert:LocalMachineMy |
Where-Object { $_.Subject -like "*prod-hv01*" } | Select-Object -First 1
Enable-VMReplication `
-VMName "SQLServer01" `
-ReplicaServerName "dr-hv01.dr.corp.local" `
-ReplicaServerPort 443 `
-AuthenticationType Certificate `
-CertificateThumbprint $replCert.Thumbprint `
-CompressionEnabled $true `
-ReplicationFrequencySec 300 ` # 5-minute RPO
-RecoveryHistory 4 ` # Keep 4 recovery points
-VSSSnapshotFrequencyHour 4 ` # VSS-consistent snapshot every 4 hours
-ReplicaPath "D:HyperVReplicaprod-hv01SQLServer01"
# Bulk: Enable replication for all VMs on this host
Get-VM | ForEach-Object {
Enable-VMReplication -VMName $_.Name `
-ReplicaServerName "dr-hv01.dr.corp.local" `
-ReplicaServerPort 80 `
-AuthenticationType Kerberos `
-CompressionEnabled $true
Write-Host "Enabled replication: $($_.Name)" -ForegroundColor Green
}
Step 3: Perform Initial Replication
# On the PRIMARY HOST
Import-Module Hyper-V
# Start initial replication (sends full copy of VM to replica)
# This can take hours for large VMs — schedule during off-hours
Start-VMInitialReplication -VMName "WebServer01"
# For large VMs, use offline initial replication:
# Export the VM, ship storage to DR site, import, then start "FromMedia" replication
Start-VMInitialReplication -VMName "SQLServer01" `
-InitialReplicationType ExportImport `
-DestinationPath "\tempshareInitialReplica"
# Monitor initial replication progress
$vmName = "WebServer01"
do {
$repl = Get-VMReplication -VMName $vmName
$progress = $repl.InitialReplicationProgress
Write-Host "$(Get-Date -f HH:mm:ss) - $vmName initial replication: $progress% ($($repl.State))"
Start-Sleep 30
} while ($repl.State -eq "InitialReplicationInProgress")
Write-Host "Initial replication complete for $vmName"
# View replication status for all VMs
Get-VMReplication | Select-Object VMName, State, Health, PrimaryServerName, ReplicaServerName,
LastReplicationTime | Format-Table -AutoSize
Step 4: Configure Extended Replication (Second Copy)
# Extended Replication sends replicas to a third site
# This requires an Extended Replica Server (third Hyper-V host)
# On the EXTENDED REPLICA HOST (dr2-hv01.dr2.corp.local)
Set-VMReplicationServer `
-ReplicationEnabled $true `
-AllowedAuthenticationType Kerberos `
-DefaultStorageLocation "E:HyperVExtendedReplica"
Enable-NetFirewallRule -Name "VIRT-HVRHTTPL-In-TCP-NoScope"
New-VMReplicationAuthorizationEntry `
-AllowedPrimaryServer "dr-hv01.dr.corp.local" ` # Replica acts as primary for extended
-ReplicaStorageLocation "E:HyperVExtendedReplicadr-hv01" `
-TrustGroup "DRSite"
# On the REPLICA HOST — enable extended replication
Set-VMReplication -VMName "WebServer01" `
-ExtendedReplication $true `
-ExtendedReplicaServerName "dr2-hv01.dr2.corp.local" `
-ExtendedReplicaServerPort 80 `
-ExtendedReplicaAuthenticationType Kerberos
Start-VMInitialReplication -VMName "WebServer01" -ExtendedReplication
Step 5: Test Failover
Test failover starts a copy of the replicated VM on the Replica host without impacting production. It uses a recovery snapshot to create an isolated test environment:
# On the REPLICA HOST
Import-Module Hyper-V
# Start a test failover (non-disruptive — does NOT affect primary or replication)
Start-VMFailover -VMName "WebServer01" -AsTest
# The test VM starts from the latest recovery point
# It is isolated — no network connectivity to production by default
# Test your application, then stop the test
# Stop the test failover (does NOT promote, just cleans up the test VM)
Stop-VMFailover -VMName "WebServer01"
# To test from a specific recovery point
Get-VMRecoverySnapshot -VMName "WebServer01" |
Select-Object Name, SnapshotTime | Format-Table -AutoSize
# Test from a specific snapshot
$snapshot = Get-VMRecoverySnapshot -VMName "WebServer01" |
Sort-Object SnapshotTime -Descending | Select-Object -First 2 | Select-Object -Last 1
Start-VMFailover -VMName "WebServer01" -VMRecoverySnapshot $snapshot -AsTest
Step 6: Perform Planned and Unplanned Failover
# PLANNED FAILOVER (scheduled maintenance — ensures zero data loss)
# Step 1: On PRIMARY, stop replication so changes are sent
# This waits for all pending replication to complete
Suspend-VMReplication -VMName "WebServer01"
# Step 2: On PRIMARY, initiate planned failover
# This shuts down the primary VM and completes replication
Start-VMFailover -VMName "WebServer01" -Prepare
# Shut down primary VM
Stop-VM -Name "WebServer01" -Force
# Step 3: On REPLICA HOST, complete the failover
Start-VMFailover -VMName "WebServer01"
# Start the replica VM
Start-VM -Name "WebServer01"
# Step 4: Reverse replication (replicate back to primary when primary is restored)
Set-VMReplication -VMName "WebServer01" -Reverse
Start-VM -Name "WebServer01" # On the replica
# UNPLANNED FAILOVER (site disaster — potential data loss equal to last RPO)
# On REPLICA HOST — perform emergency failover
Start-VMFailover -VMName "WebServer01"
Start-VM -Name "WebServer01"
Write-Host "Unplanned failover complete for WebServer01. RPO data may be lost."
Step 7: Monitor Replication Health
function Get-ReplicationHealthReport {
param([string]$ComputerName = "localhost")
$replVMs = Get-VMReplication -ComputerName $ComputerName
$report = $replVMs | ForEach-Object {
[PSCustomObject]@{
VMName = $_.VMName
State = $_.State
Health = $_.Health
LastReplication = $_.LastReplicationTime
MissedReplication = $_.MissedReplicationCount
PendingSize = "$([math]::Round($_.PendingReplicationSize/1MB,2)) MB"
AverageLatency = "$($_.AverageReplicationSize) bytes"
}
}
$unhealthy = $report | Where-Object { $_.Health -ne "Normal" }
if ($unhealthy) {
Write-Warning "Unhealthy replication detected for $($unhealthy.Count) VM(s):"
$unhealthy | Format-Table -AutoSize
}
$report | Export-Csv "C:ReportsReplicationHealth_$(Get-Date -f yyyyMMdd_HHmm).csv" -NoTypeInformation
$report | Format-Table -AutoSize
}
Get-ReplicationHealthReport -ComputerName "prod-hv01.corp.local"
Verification
# Comprehensive Hyper-V Replica verification
Write-Host "=== Hyper-V Replica Status ===" -ForegroundColor Cyan
# All VMs and their replication state
Get-VMReplication | Sort-Object Health |
Select-Object VMName, Mode, State, Health, LastReplicationTime, MissedReplicationCount |
Format-Table -AutoSize
# Replica server configuration
Get-VMReplicationServer |
Select-Object ReplicationEnabled, AllowedAuthenticationType, DefaultStorageLocation |
Format-List
# Recovery point counts
Get-VM | Where-Object { (Get-VMReplication -VMName $_.Name -ErrorAction SilentlyContinue) } |
ForEach-Object {
$snapshots = Get-VMRecoverySnapshot -VMName $_.Name
Write-Host "$($_.Name): $($snapshots.Count) recovery points available"
}
Summary
Hyper-V Replica on Windows Server 2012 R2 delivers a cost-effective, built-in disaster recovery solution that requires no shared storage or third-party tools. By configuring the Replica server to accept connections, enabling replication on each production VM, completing the initial replication, testing failover in a non-disruptive mode, and monitoring replication health through PowerShell, you achieve continuous VM replication to a secondary site with RPOs as low as 5 minutes. The planned failover path ensures zero data loss for scheduled maintenance, while the unplanned failover path provides rapid recovery from site disasters. Extended Replication adds a third copy for organizations needing additional geographic redundancy.