Resume Hyper-V replication after server reboot with PowerShell
This PowerShell script will resume Hyper-V machine replication after a server reboot. I schedule it to run each morning. It will write the status to a local log file and will only modify the replica status of the virtual machine if it does not equal Normal.
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
#Script by Allan Brochorst Kjær, May 2016 | |
date >>c:\VMReplication_status_log.txt | |
$ServerStatOK = Get-VMReplication | Where-Object {$_.ReplicationHealth -eq "Normal"} | |
foreach ($i in $ServerStatOK) | |
{ | |
Write-Host $i.VMName $i.ReplicationHealth | |
echo $i.VMName "sync status is:" $i.ReplicationHealth >>c:\VMReplication_status_log.txt | |
} | |
$ServerStatFail = Get-VMReplication | Where-Object {$_.ReplicationHealth -ne "Normal"} | |
foreach ($i in $ServerStatFail) | |
{ | |
Write-Output $i.VMName "replicationstatus is" $i.ReplicationHealth >>c:\VMReplication_status_log.txt | |
Resume-VMReplication $i.VMName | |
Reset-VMReplicationStatistics $i.VMName | |
Write-Output $i.VMName "replicationstatus is now" $i.ReplicationHealth >>c:\VMReplication_status_log.txt | |
} | |
date >>c:\VMReplication_status_log.txt | |
echo _____SCRIPT_ENDS_HERE_____ >>c:\VMReplication_status_log.txt |
Kommentarer
Send en kommentar