Create DFS Replication Healthcheck email report

DFS-R is the replication component of the Distributed File System (DFS). Windows Server 2012R2 introduces powershell cmdlets that can be used for management rather thsn relying on the old dfsutil commands.

Some of the common issues with DFS-R are files not replicating due to network latency or connectivity issues. The knock on effect leads to staging folders becoming full leading and file replication stopping.

If you dont have SCOM or other monitoring tools at hand to monitor DFS-R. The code below can be saved as a ps1 poweshell script and scheduled to run on one of the DFS-R servers. The script generates a healthcheck report and sends the report by email.

Amend the variables at the start to define replication group and email server/recipent/sender details.

Additonal DFS servers can be specified by extending the Write-DfsrHealthReport command by adding the “$DFSservers[..]” variable with array index value.

$DFSGroupName ="Enter DFS Replication group name here"
$DFSservers = (Get-DfsrMembership -GroupName $DFSGroupName |select -ExpandProperty computername)
$foldernamedate = $(get-date -f dd-MM-yyyy)
$source = "C:\DFSReportsImport\"
$destination = "C:\DFSReportsExport\$foldernamedate\DFS_Report.zip"
$emailServer = "mysmtpserver.example.com"
$sender = "sender@example.com"
$recipients = "recipient@example.com"
mkdir c:\DFSReportsImport\$foldernamedate
mkdir c:\DFSReportsExport\$foldernamedate
Write-DfsrHealthReport -GroupName $DFSGroupName -ReferenceComputerName $DFSservers[0] -MemberComputerName $DFSservers[0], $DFSservers[1] -CountFiles -Path c:\DFSReportsImport\$foldernamedate\

Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($source, $destination)
remove-item -path c:\DFSReportsImport\$foldernamedate -Recurse -Force
send-mailmessage -from $sender -to $recipients -subject "DFS Report $foldernamedate" -Body "DFS Report generated from $DFSservers[0]" -smtpserver $EmailServer -attachments "C:\DFSReportsExport\$foldernamedate\DFS_Report.zip"
remove-item -path c:\DFSReportsExport\$foldernamedate -Recurse -Force

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s