Testing DFS Replication with Powershell

DFS Replication (DFS-R) is a fantastic tool in any sysadmins belt when it comes to creating highly redundant and scalable file shares. And yet anyone who has used it, knows that monitoring it can be difficult at the best of times.

Windows Server 2012 introduced a number of Powershell commands for DFS-R which help discover partnerships and their status, however none of them test replication end-to-end.

So here are the goals I get out to achieve with Powershell:

  • Test a file replicates successfully between 2 servers using DFS-R
  • Fail the test if the file doesn’t replicate within a expected time period
  • Dynamically discover replicated folders
  • Dynamically discover replication groups
  • Dynamically discover replication partners
  • Run both locally and remotely

If you don’t want to learn how the code works, you can skip to the examples of the script in action, or just download the script here.

Building the Code

The first step is pretty straight forward, create a file and test it arrives at the other side.

Now to make sure this loop doesn’t run forever if replication isn’t working or there is a large backlog, we need to add a timeout. To do this, we’ll use the stopwatch function.

The last 3 steps we can tick off at the same time using DFS-R in-box Powershell to help us. Get-DFSRConnection can be used to query a machine for what connections it’s part of, this tells us the group names and the destination servers. With this information we can then use Get-DFSRMembership to query the folder names and paths to test.

We now have a way to test the folders that a server is replicating using DFS-R are actually working. To make this a bit more reusable, I turned the above code into a script that can be fed specific parameters.

Meet Test-DfsrReplication, a script you can use to test one or more servers, either for a specific folder or all folders. Not only that, but it will test replication in both directions.

You can download an up-to-date copy of it any time from my Github account here.

Examples

And here are some examples of it in action!

As always, please comment if you have any further questions or have found this useful!

One thought on “Testing DFS Replication with Powershell

  1. Could you give some input in how i should think about my quotas and size em? And how you generally go about it? I have like 20 shares between 2 offices.
    Also some norr maybe troubleshooting dfsr 🙂

    Br
    Nick

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.