Power Shell Script to show the status of Hyper Replication.
$ReplicatedVMs = Get-VMReplication;
If ($ReplicatedVMs.Length -GT 0) {
# VMs with replication enabled found
# Document VM replication health
ForEach ($VM in $ReplicatedVMs) {
If (($VM.ReplicationHealth -Eq “Warning”) -Or ($VM.ReplicationHealth -Eq “Critical”)) {
# Current VM has replication issues
# Add current broken VM’s relevant objects to multidimensional array
$ReplicatedVMs_Broken += ,@($VM.VMName, $VM.ReplicationHealth);
}
# Add current VM’s relevant objects to multidimensional array
$ReplicatedVMs_All += ,@($VM.VMName, $VM.ReplicationHealth);
}
# Generate output part 1/2 and MAX RemoteManagement exit codes
If ($ReplicatedVMs_Broken.Length -Eq 0) {
# VM replication issues not found
Write-Host “SUCCESS. Found no VMs with replication issues. Details:”;
# Set exit code to pass MAX RemoteManagement check
$ExitCode = 0;
} Else {
# VM replication issues found
Write-Host “FAIL. Found VMs with replication issues. Details:”;
# Set exit code to fail MAX RemoteManagement check
$ExitCode = 1;
}
# Generate output part 2/2
For ($i = 0; $i -NE $ReplicatedVMs_All.Length; $i++) {
$Output = ‘VM “‘ + $ReplicatedVMs_All[$i][0] + ‘” replication health “‘ + $ReplicatedVMs_All[$i][1] + ‘”‘;
Write-Host $Output;
}
} Else {
# Found no VMs with replication enabled
Write-Host “Found no VMs with replication enabled.”;
# Set exit code to pass RemoteManagement check
$ExitCode = 0;
}
Exit $ExitCode;