Fully automated PowerShell script that uses Get-DfsrBacklog to collect backlog information for all replication groups and replicated folders in all sources and destinations, excluding Domain System Volume (SYSVOL).


Important note: this script is provided "as-is", with no warranties or guarantees. Support and updates will be provided reactively upon discovering errors.

 

This script uses the following cmdlets to automate the data collection:

 

The script can be executed in any server that has DFSR binaries installed and is developed to support from Windows Server 2012 to Windows Server 2016.

This script is a secondary version to my other DFSR Backlog script. The reason for that is purely performance and backward compatibility. While the first supports Windows Server 2008 R2 and Windows Server 2008, this one is supposed to run in Windows Server 2012 or above and offers better performance overall.

When compared to the previous version, this version has its upsides in three main points: better overall performance as we're working with (mainly) PowerShell objects, better error handling due to -ea and -ev switches and better replication route handling due to Get-DfsrMember and Get-DfsrConnection cmdlets.

This script includes visual feedback, reporting the status of each replicated folder from source to destination with colors:

Each time backlog is encountered, the list containing the first 100 files queued will be exported to the chosen path, which defaults to \temp\DFSR. If the said path doesn't exists, the script will then create it. A timestamp will be added to each file in order to ensure uniqueness.

The path can be changed at anytime to any path of your desire:

PowerShell
Edit|Remove
# Creating directory 
$path = "C:\temp\DFSR"New-Item -ItemType Directory -Force -Path $path | Out-Null;
PowerShell
Edit|Remove
# Function 
Function getbacklog 
{ 
    # Resetting error variable 
    $err = $null 
     
    # Getting backlog count with Get-DfsrBacklog 
    $backlog = Get-DfsrBacklog -GroupName "$group" -FolderName "$folder" -SourceComputerName "$member" -DestinationComputerName "$destination" -ea SilentlyContinue -ev err; 
     
    If ($err -ne $null) 
    { 
        Write-Host "Error retrieving backlog for folder $folder on replication group $group, from:$member to:$destination. To troubleshoot the error, please run <Get-DfsrBacklog -GroupName $group -FolderName $folder -SourceComputerName $member -DestinationComputerName $destination -Verbose> separately." -foreground red; 
    } 
    Else 
    { 
        $backlogcount = (Get-DfsrBacklog -GroupName $group -FolderName $folder -SourceComputerName $member -DestinationComputerName $destination -Verbose 4>&1).Message.Split(':')[2]; 
         
        # Formatting backlog count and preparing the output string 
        If ($backlogcount -eq $null) 
        { 
            Write-Host "Backlog for replicated folder $folder on replication group $group, from:$member to:$destination, is 0." -foreground green; 
        } 
        Else 
        { 
            $date = Get-Date -f yyyy-MM-dd-HH-mm-ss; 
            # Exporting file queue information out of the Get-DfsrBacklog cmdlet output 
            $backlog | ft Index,FileName | Out-File $path\backlog.txt; 
            (Get-Content $path\backlog.txt).trim() | Set-Content $path\backlog.txt; 
            Rename-Item $path\backlog.txt Backlog-$($date)-$($folder)-$($group -replace "[\/\\]""-")-$($member)-$($destination).txt; 
            Write-Host "Backlog for replicated folder $folder on replication group $group, from:$member to:$destination, contains $backlogcount file(s) queued. The list for the first 100 files queued can be found on $path\Backlog-$date-$folder-$group-$member-$destination.txt" -foreground yellow; 
        } 
    } 
} 
 
# Creating directory 
$path = "C:\temp\DFSR"New-Item -ItemType Directory -Force -Path $path | Out-Null; 
 
# Getting replication group information 
$groups = (Get-DfsReplicationGroup | Select -expand GroupName).trim(); 
 
# Looping each replication group found 
Foreach ($group in $groups) 
{ 
    # Getting all replicated folders for replication group $group 
    $folders = (Get-DfsReplicatedFolder "$group" | Select -expand FolderName).trim(); 
     
    # Looping each replicated folder found for group $group 
    Foreach ($folder in $folders) 
    { 
        # Getting all members for replication group $group 
        $members = (Get-DfsrMember "$group" | Select -expand ComputerName).trim(); 
         
        # Looping each member found for replication group $group 
        Foreach ($member in $members) 
        { 
            # Getting all destination servers for member $member on replication group $group 
            $destinations = (Get-DfsrConnection -GroupName "$group" -SourceComputerName "$member" | Select -expand DestinationComputerName).trim(); 
             
            # Looping each destination found for member $member on group $group 
            Foreach ($destination in $destinations) 
            { 
                Getbacklog; 
            } 
        } 
    } 
}