Hyper-V Replica: Basic Monitoring Report

Earlier I covered what my Hyper-V Replica setup looks like in this post.  It’s basically four laptops on my coffee table, all part of the same AD domain.

I created a number of VMs on the systems, and configured replication, including extended replication for a couple of the VMs, as per the picture below:

Like I said earlier, what a mess of replication I’ve created! 
How could I possibly keep track of it all, as well as effectively monitor replication?

Truth be told I created this mess so I could create a report!  I was inspired somewhat by on of Ben Armstrong’s post about his home configuration. 
Ben created a nice little PowerShell one-liner that created a simple, easy to read report detailing replication status on a single host.

get-vm | Get-VMReplication | select name, replicationmode, replicationhealth, @{Expression={"{0:N0}" -f ((get-date)-($_.lastreplicationtime)).TotalMinutes};Label="Delta (min)"}

…and the output looked like this:

It’s a nice little bit of code…Ben did some things with time to make the replication delta time appear in minutes – very cool.

I wanted to shoot for something a little more ambitious.  I wanted to report on multiple servers (to help with monitoring  remote branch / store locations), as well as make it sortable.  Ben’s output didn’t show any of the host names or the assigned replication interval, and (as is the way with PowerShell) it looked sort of old school with the output sitting inside the PowerShell Window.

I tweaked Ben’s one-liner a tiny bit.  First I created a text file on one of the hosts (c:\Serverlist.txt) with the names of my Hyper-V hosts, so I could loop through them:


I know that I could have simply asked AD for all the Hyper-V hosts it knows about, but I wanted to create a simple example (and no, I don’t own replicatest.com – I’m not running this on the Interwebs … just using the name on my coffee table!).

Then add some missing fields and pipe it to one of my favorite PowerShell cmdlets Out-Gridview:

get-content .\serverlist.txt | foreach-object {get-vm -computername $_ } | where {$_.replicationstate -notmatch "Disabled"} | get-VMreplication | select primaryserver, replicaserver, name, replicationmode, State, replicationhealth, @{Expression={"{0:0.0}" -f ($_.FrequencySec / 60)};Label="Target Freq (min)"}, @{Expression={"{0:N0}" -f ((get-date)-($_.lastreplicationtime)).TotalMinutes};Label="Delta (min)"} | out-gridview

The output is a sortable, filterable GUI (via Out-Gridview) with all the critical info I think I would need to monitor the status of Hyper-V Replica on my servers:


PowerShell is awesome… but I must confess that I don’t use it everyday, so I have to poach great examples and fiddle a lot .

Still, what’s great about the basics of the one-liner that I snagged from Ben is that it can be used in any number of ways – it could be updated to to create a simple exception report for VMs with an “Error” for replication State, to find VMs not configured for replication…whatever.

The great thing is that this “one-liner” let me easily see (and unwind) the multi-server replication I had created!