Skip to content

Instantly share code, notes, and snippets.

@michyprima
Created June 1, 2022 08:21
Show Gist options
  • Save michyprima/3eccd9c5bada783a95245205e893fb01 to your computer and use it in GitHub Desktop.
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)
$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