Powershell script to generate and email a DFS Health Report.

This script was used to generate a DFS Health Report and email it to the admin team on a daily basis.

I attempted to push the report into the body of the email but Outlook did not like the formatting so instead it was added as an attachment.
This is on a Windows 2008 R2 Server using the old commandline version of DFS and its reporting. The Report does not work in some of the newer version of IE.
To view the report you have to hit F12 and then change the Document Mode: IE quirks to IE5 Quirks

#    Copyright 2011 Robert Stacks
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
# Author: Robert Stacks
# URL: RandomTechMinutia.wordpress.com
# Date: 11/30/2012
# Updated: 11/30/2012
# Version: 0.1
# Purpose:
# Generate a DFS Admin Report and Email it to the admin team it must be viewed with IE due to HTML/Java formatting

#Get todays Date
$date = Get-Date

#User Adjustable Variables  #

#Mail Server Variables
$SMTPserver = "mail.domain.com"
$from = "DFSReplicationReport@domain.com"
$to = "Youremail@domain.com"
$subject = "DFS Replication Health Report " + $date
$emailbody = "Attached is the Report"

#DFS Info
#Note: $ReplicationGroup=`"Corp Office to Phoenix`", if your group name has no spaces you can remove the `"
#the dfsadmin command can be a little unforgiving about quotes you may have to adjust your values accordingly.

$ReplicationGroup=`"Your Replication Group`"

#Main Script                #

#Generate DFS Report

dfsradmin health new /RgName:$ReplicationGroup /RefMemName:$MemeberServer /repname:$SaveReportLocation

# Send email
Send-MailMessage -From $from -To $to -SmtpServer $SMTPserver -Subject $subject -Body "Attached is the DFS Health Report. It must be viewed in IE" -Attachments ("C:\DFSReports\Health-Corp Office to Phoenix.html")

  1. #1 by heintraag on October 29, 2013 - 10:32 am

    Nice script but it has one flaw.. it only send the html without the xml.. which results in a html you cannot use. How can i have it send both files?

    • #2 by Robert on January 20, 2014 - 8:41 am

      I use this daily.
      That being said there is not xml file per say. The encoding is specific to IE. If you are using IE 10 or 11 it doesn’t even support the format. To view you have to hit F12 and then change the Document Mode: IE quirks to IE5 Quirks. The newer version of Windows/Powershell includes some new tools to manage DFS but I haven’t had a chance to play with those yet. I’ll be updating this script when I do. -Robert

  2. #3 by heintraag on January 20, 2014 - 8:46 am

    Hi Robert. We’ll wait for the updated script. Sure could use it, saves us the trouble manually checking if DFS is working properly 🙂 Thanks for the script.

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

%d bloggers like this: