Running this script in the PowerShell ISE will give you a nice output comparing the server you’re running it on with the other connection members in the replication group(s) it belongs to.

You will see “warnings” highlighted in yellow and “errors” highlighted in red.

  • Since this was ran in a production environment I had to blur out the server names and replication group names.

 

 

It uses WMI to query the DFS Replication Groups and further gather the backlog statistics.

 

Copy the code below into PowerShell ISE and run it!

 

I have modified the script for my environment to send the results via e-mail, but I’d like to polish that up a little more if I am going to share it.

 

I hope this helps you!

 

Update 2/6/2018:

I updated the script with ability to email the results.

At line 31 it starts a transcript of the PS session and saves it at C:\scripts\dfsr1.txt

Lines 100 and beyond are where the output file is processed for email and actually sent.

  • I was sending through an open mail relay that does not need authentication.
  • If you need authentication for the SMTP server,  you will have to modify the Send-MailMessage line

 

 


13 Comments

David · October 23, 2019 at 10:44 am

Just what I was looking for so many thanks – but…. like John above what I get emailed is not what is shown on screen. As the script runs, the dfsr1.txt file builds correctly but what is emailed is only a partial.

This is a snapshot of the file as the script runs…

Windows PowerShell transcript start
Start time: 20191023162958
Username: MSI\msisvc
RunAs User: MSI\msisvc
Machine: MSI-DATA-02 (Microsoft Windows NT 6.3.9600.0)
Host Application: powershell
Process ID: 4988

Transcript started, output file is c:\scripts\DFSRBackLog\dfsr1.txt
212117 files in backlog WBS-DATABAK->MSI-DATA-02 for msi.net\msi\data
0 files in backlog MSI-DATA-01->MSI-DATA-02 for msi.net\msi\data
0 files in backlog MSI-DATA-02->MSI-DATA-01 for msi.net\msi\data

which all is good & correct – but at the end, what is emailed is:

6 successful, 0 warnings and 2 errors from 8 replications.

Windows PowerShell transcript end
End time: 20191023163922

If I rem out the “Remove-Item c:\scripts\DFSRBackLog\dfsr1.txt” line that is the file which is left in the dir as well..

Anyway, thanks for sharing!

    David · October 23, 2019 at 10:46 am

    and on screen it looked fine….

    PS C:\Scripts\DFSRBackLog> ./dfsrbacklogcount2.ps1
    Transcript started, output file is c:\scripts\DFSRBackLog\dfsr1.txt
    90182 files in backlog WBS-DATABAK->MSI-DATA-02 for msi.net\msi\data
    0 files in backlog MSI-DATA-01->MSI-DATA-02 for msi.net\msi\data
    0 files in backlog MSI-DATA-02->MSI-DATA-01 for msi.net\msi\data
    2223606 files in backlog MSI-DATA-02->WBS-DATABAK for msi.net\msi\data
    0 files in backlog MSI-DATA-01->MSI-DATA-02 for msi.net\wbs\data
    0 files in backlog WBS-DATA-01->MSI-DATA-02 for msi.net\wbs\data
    0 files in backlog MSI-DATA-02->MSI-DATA-01 for msi.net\wbs\data
    0 files in backlog MSI-DATA-02->WBS-DATA-01 for msi.net\wbs\data
    6 successful, 0 warnings and 2 errors from 8 replications.
    Transcript stopped, output file is C:\scripts\DFSRBackLog\dfsr1.txt
    PS C:\Scripts\DFSRBackLog>

      David · October 23, 2019 at 10:58 am

      OK, sorted it….

      The problem is this block of code @ line 102.

      get-content $file |
      select -Skip 18 |
      set-content “$file-temp”
      move “$file-temp” $file -Force

      The -Skip 18 I guess refers to Tyler’s environment but with more DFSR servers then the output will be truncated so the ’18’ needs adjusting to your own taste.

      Once again Tyler, many thanks

      David

        Tyler Woods · October 23, 2019 at 11:18 am

        ahhh yes this is a classic “me” move. it applies specifically to my environment and I haven’t accounted for differences in others!

        thank you for sharing your experience.

          David · October 23, 2019 at 11:49 am

          Thanks Tyler – not a problem as it’s a great script.

          OOI, and to help educate us all, how, if you have time, is the value of 8 that you use calculated? I ‘fixed’ it by trial and error.. ;{

Nathan Dear · September 2, 2019 at 11:38 pm

Hi Tyler,

What a great script! Does exactly what I need it to do.

Don Hessey · March 20, 2019 at 9:37 am

How would you get a list of the actual backlogged files in the text file as well?

    Tyler Woods · March 20, 2019 at 10:26 am

    There are two ways to do this:

    1)
    dfsrdiag backlog /rgname:"REPLICATION_GROUP_NAME" /rfname:"REPLICATED_FOLDER_NAME" /smem:"SERVER_1" /rmem:"SERVER_2"

    2)
    Get-DfsrBacklog -DestinationComputerName "SRV1" -SourceComputerName "SRV02" -GroupName "RG01" -FolderName "RF1" | format-table fullpathname,updatetime

    more about get-dfsrbacklog

John · April 25, 2018 at 11:04 am

Hi Tyler, this is a nice script. I was looking for this long time. Great job.
I am getting all result on the screen , but not in the email body.
The email body is listing only the last three lines.Any suggestions?

    Tyler Woods · April 25, 2018 at 2:37 pm

    Did you copy+paste from the example I shared? I’m not able to test this against an environment right now, but I pulled that snippet from my repository of production scripts.

    I would ensure the start-transcript is up at the proper location, and you can also double check the .TXT file to see what its contents are as a way to diagnose if the problem is with sending the body of the message or with saving the transcript of the session.

    thanks!

Nick · February 7, 2018 at 8:32 am

Hi Tyler, this is great, thanks!
Did you ever get the emailing of results part working?
Thanks

    Tyler Woods · February 7, 2018 at 8:49 am

    Yes I did! I am going to update the post since posting the script in the comments doesn’t exactly work well. Thanks!

    Tyler Woods · February 7, 2018 at 8:58 am

    Nick, the post has been updated with the method I used for emailing the results.

Leave a Reply