Created
August 29, 2022 05:17
-
-
Save dpo007/0c8f0fd4676b3dfdc9e243d0e1b374b3 to your computer and use it in GitHub Desktop.
PowerShell :: Configure Hyper-V replication between a set of host servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Configures Hyper-V replication between a set of host servers. | |
v1.0 - DPO - Aug. 2022 | |
#> | |
#Requires -RunAsAdministrator | |
#Requires -Version 5.1 | |
param ( | |
[string]$HostReplicaFolderPath = 'D:\ReplicaVMs', | |
[switch]$LeaveExistingAllowedServers | |
) | |
$hvHosts = @( | |
'HV-VMHost1.corp.company.com', | |
'HV-VMHost2.corp.company.com', | |
'HV-VMHost3.corp.company.com', | |
'HV-VMHost4.corp.company.com' | |
) | |
# Prepare variables for internal use. | |
$HostReplicaFolderPath = $HostReplicaFolderPath -replace '\\$' | |
$hostReplicaFolderAdminUNC = $HostReplicaFolderPath -replace '^(.):\\','$1$\' | |
foreach ($hvHost in $hvHosts) { | |
# Configure and enable HyperV replication on current server. | |
Set-VMReplicationServer -ComputerName $hvHost ` | |
-ReplicationEnabled $true ` | |
-AllowedAuthenticationType Kerberos ` | |
-ReplicationAllowedFromAnyServer $false ` | |
-KerberosAuthenticationPort 80 ` | |
-CertificateAuthenticationPort 443 | |
# Create folder on host server to hold replica VMs. | |
mkdir ('\\{0}\{1}' -f $hvHost, $hostReplicaFolderAdminUNC ) -Force | |
if (!$LeaveExistingAllowedServers) { | |
# Wipe all existing Allowed Servers. | |
Get-VMReplicationAuthorizationEntry -ComputerName $hvHost ` | |
| Remove-VMReplicationAuthorizationEntry | |
} | |
# Populate Allowed Servers list with other host servers. | |
foreach ($allowedHvHost in $hvHosts) { | |
if ($allowedHvHost -ne $hvHost) { | |
# Create a subfolder to hold the replica VMs from other host server. | |
mkdir ('\\{0}\{1}\From_{2}' -f $hvHost, $hostReplicaFolderAdminUNC, $allowedHvHost) -Force | |
# Add host server to the Allowed Servers list. | |
New-VMReplicationAuthorizationEntry -ComputerName $hvHost ` | |
-AllowedPrimaryServer $allowedHvHost ` | |
-TrustGroup 'Our Company HV Host Servers' ` | |
-ReplicaStorageLocation ('{0}\From_{1}' -f $HostReplicaFolderPath, $allowedHvHost) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment