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.

#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

Populære opslag fra denne blog

Microsoft Office 2016 and the AUTO_ACTIVATE property

Access Exchange online with Office 365 multi-factor authentication (MFA/2FA)

Disable logon and logoff events (event id 4624, 4625, 4634 (and all the other ones...))