How do I get the current DFS replication backlog count?

green

The below script will dynamically get all DFS replication groups, servers, and folders, and output the backlog count for each (in every replication direction).  No modification is required – just copy/paste into an Administrative PowerShell window.

Ensure you perform this on a server with the DFS tools installed (the script calls dfsradmin and dfsrdiag)

 

 

The output should hopefully be all zeroes.  If if looks like the below, you have a problem…

dfs

green

8 Comments How do I get the current DFS replication backlog count?

  1. Tawney Follett

    Hi Kamal,

    I found that in some cases (and I think this occurred with longer server names) that the Trim whitespace function was not yeilding the correct results.

    I found that in some cases there were numerous additional whitespaces so I changed the code to (on line 37 and 38):

    $sendingserver = ($replicationserver.split()| where {$_})[0].trim();
    $receivingserver = ($replicationserver.split()| where {$_})[1].trim();

    I found if all of my servers had the same length names, your original code wouldn’t be a problem; but if some had different length names then this issue would occur because on a few lines of code there would be 2 spaces between sending and receiving server and then on other lines of code there would be 4 spaces between sending and receiving server due to being shorter length names on that column.

    Thanks

    Tawney

    Reply
  2. Justin

    I can’t seem to get this working on 2008 R2 servers, only 2012 R2. For example, the output below. I tried Tawney’s tweak but that didn’t help either. Perhaps a Powershell version issue?

    Replication group with name Support cannot be found.
    Cannot index into a null array.
    At C:\Users\administrator\Desktop\dfsr_replication.ps1:21 char:51
    + $replicationfolder = (($replicationfolder[ <<<< 1].split("\"))[0]).trim();
    + CategoryInfo : InvalidOperation: (1:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Reply
    1. Kamal

      Looks like the returned object from the dfsradmin command isn’t working correctly. I’d start troubleshooting this by running the command separately (and determining where to go from there) – ie; dfsradmin rf list /rgname:

      Reply
  3. Paul Raikes

    This script is exactly what I was looking for. Is there an easy way to take that output and email it through PS? Creating a scheduled task to send a daily email would be beneficial.

    Thanks in advance.

    Reply
    1. Kamal

      Creating a schedule task is pretty straightforward, just need to save the script in a .ps1 file, then call powershell.exe -f filename.ps1 within the scheduled task. The command to send emails is send-mailmessage (https://technet.microsoft.com/en-us/library/hh849925.aspx) – and I like using the -BodayAsHTML option.

      I don’t like any of the automated conversions to HTML, so I often build the HTML file as a variable, as I go. EG:

      – and then start appending to that variable as you loop through the data in the regular script (usually adding tables, and tr elements inside the loops). This variable then becomes the body of your email.

      A couple of things to be aware of, as well:

      – you need the change the Remote Execution Policy to allow the script to run from a scheduled task (https://technet.microsoft.com/en-us/library/hh849812.aspx). Something like “set-executionpolicy unresitricted -scope LocalMachine”.

      – You need to set the scheduled task to allow it to run when no one is logged in with elevated privileges (checkboxes in Task Scheduler).

      – The account you’re running the scheduled task as, needs “log on as a batch job” rights (Local Admin, or set for a specific account with these rights through Local Policy or Group Policy). (https://technet.microsoft.com/en-us/library/cc957131.aspx)

      Reply
  4. Gary Leung

    I know you mention the send-mailmessage to send the results via email but where in the script do I enter that command? Sorry still new PS scripting.

    Reply

Leave a Reply

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