Created
June 1, 2022 08:21
-
-
Save michyprima/3eccd9c5bada783a95245205e893fb01 to your computer and use it in GitHub Desktop.
Powershell: Auto resync critical Hyper-V VMs one at a time (Windows Server 2019 VM Replication)
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
$ReplicationData = Get-VMReplication | |
$ok = $true | |
$lastwait = $false | |
Do { | |
$ok = $true | |
Foreach ($VMReplica in $ReplicationData) { | |
If ($VMReplica.State -eq "Resynchronizing") { | |
if ($lastwait -ne $VMReplica) { | |
Write-Host "Attesa fine sincronizzazione di" $VMReplica.Name | |
$lastwait = $VMReplica | |
} | |
$ok = $false | |
Break | |
} | |
} | |
If ($ok -eq $true) { | |
Foreach ($VMReplica in $ReplicationData) { | |
If ($VMReplica.Health -eq "Critical") { | |
$ok = $false | |
Write-Host "Avvio replica di" $VMReplica.Name | |
Resume-VMReplication -VMName $VMReplica.Name -Resynchronize | |
Break | |
} | |
} | |
} | |
if ($ok -eq $false) { | |
start-sleep -s 5 | |
} | |
} Until ($ok) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment