Powershell – Check DFS Backlog Windows Server 2012 R2

The DFS Get-DFSRBacklog cmdlet is OK, but the problem is that by default it only reports  a maximum of 100 files in the backlog. The following script shows you have to get the real amount and it looks so you can keep any eye on it increasing or decreasing!

If you run the Get-DFSRBacklog cmdlet , it will return a count of 100 maximum. Which is not any real use if you are wanting to know how long a backlog of 500,000 files is going to take – trust me – I needed to know!

If you run the cmdlet with the -Verbose parameter will tell you exactly how many are in the queue, but how do you get that into a format you can report on?

First you have to redirect the verbose output stream to the success output stream

Scroll to the bottom to see the code.

So basically the

 4>&1

redirect the verbose  to the success stream

Then we wrap the command in brackets to return the result and process it a bit more

(Get-DfsrBacklog -Groupname "RG01" -FolderName "Cache"  -SourceComputerName Srv1 -DestinationComputerName Srv2 -verbose 4>&1)

If you pipe the command through get- member

(Get-DfsrBacklog -Groupname "RG01" -FolderName "Cache"  -SourceComputerName Srv1 -DestinationComputerName Srv2 -verbose 4>&1) |get-member

You will see that there is a message property. So if you go

(Get-DfsrBacklog -Groupname "RG01" -FolderName "Cache"  -SourceComputerName Srv1 -DestinationComputerName Srv2 -verbose 4>&1).message

You will get the verbose message back

We then use the split() method to split the message up into an array using  the : character as the delimiter and we return the 3rd item in the array (arrays start at [0]  )

(Get-DfsrBacklog -Groupname "RG01" -FolderName "Cache"  -SourceComputerName Srv1 -DestinationComputerName Srv2 -verbose 4>&1).Message.Split(':')[2]

In the script below I just loop forever, so it just prints a time-stamped line to the console every 10 seconds to tell me how many items are in the backlog queue

 

$forever = 1

do
{
#Get the current date and time and reformat it to YYMMDDHHMM
$CurrentDatetime = Get-Date -UFormat %y%m%d%H%M
$QueueLength1 = (Get-DfsrBacklog -Groupname "RG01" -FolderName "Cache"  -SourceComputerName Srv1 -DestinationComputerName Srv2 -verbose 4>&1).Message.Split(':')[2]
write-host   $CurrentDatetime "Current Queue length equals: $QueueLength1"
start-sleep 10
}
while ($forever -gt 0)


 

 

One thought on “Powershell – Check DFS Backlog Windows Server 2012 R2

Leave a comment

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.