Checking Virtual Machine Health After a Disaster

Last weekend I suffered a human disaster in my "server room".  Which is to say that I knocked down a shelf in my garage and accidentally disconnected the UPS.  This, in turn turned off all of my hardware.  An hour later I had fixed the shelf, reconnected all the wiring and had booted the servers again. I then had to make sure all the virtual machines were up and running.  I had some problems, because one disk array did not come online automatically, but after a bit of cajoling I believed everything was good. 

However, when you are using Hyper-V Replica this can be a bit tricky to check.  You see, I have two copies of every virtual machine and one should always be off.  After switching between my two servers a couple of times to try and check the status - I decided to go to PowerShell.

Now I had a quandary. How could I check the state of all the virtual machines that should be running, while not looking at the virtual machines that should be off?  The answer soon came to me:

get-vm -computername Hyper-V-1, Hyper-V-2 | ?{$_.ReplicationMode -ne "Replica"}

"Hyper-V-1" and "Hyper-V-2" are my two Hyper-V servers (creative names, I know).  And this command returns the status of every virtual machine that is not a replica.  I then checked the replication health of just the replica virtual machines with this command:

get-vm -computername Hyper-V-1, Hyper-V-2 | ?{$_.ReplicationMode -eq "Replica"} | select Name, ReplicationState, ReplicationHealth

Which gave me these results:

With that all done - I could get back to working in my garage.

Cheers,
Ben