Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

DFSR health report and powershell script that is actually useful


  • Please log in to reply
2 replies to this topic

#1 Fardooste

Fardooste

  • Members
  • 107 posts
  • OFFLINE
  •  
  • Local time:02:48 PM

Posted 21 September 2015 - 09:34 AM

DFSR (aka DFS-R aka DFS replication) offers only basic reports. The issue I had with them is, you needed to actually open up all the reports to see if there was any issues. In this modified script, emails are sent out with the basic health and conflict info. Even better, 

1. Emails for health and conflicts are only sent if there are actually health issues or conflicts

2. The body of the sent emails for the alerts now includes the basic issue info in it, saving you troubleshooting time, as you now know where to zero in.

 

The forum sticks in line breaks.  Remove them before running this script. I stuck semicolons at the ned of the broken-up paragraphs to herlp you know where to remove the line breaks. 

 

 

 

 

 

 
# last modified : sept 21 2015 
# by fardooste
# emails only sent if there are issues with health and conflicts
# health email now includes helpful summary
 
Import-Module DFSR
 
# Write DFS Health Report for all Replication Groups
$groups = 'MarketingRep','InstallsRep','my_companyDataRep','Home', 'Shared','my_company_Data'
# edit this with your own groups
 
foreach ($group in $groups){
    $members = 'fs1,'fs2'
# change this to your own servers
    $report_parms = @{'GroupName' =             "$group";
                      'ReferenceComputerName' = $env:COMPUTERNAME;
                      'MemberComputerName' =    $members
                      'Path' =                  'c:\dfsreports\';
                      'CountFiles' =            $true  
                    }
# end of report_parms object
    
Write-DfsrHealthReport @report_parms 
}
#end of foreach loop
 
# Get the six newest files -- these were just generated by Write-DFSRHealthReport
# you might have more or less depending on your number of groups
 
cd C:\DFSReports
# del *.xml
# eliminate the generated xml files. We don't need them.
# you might want them so this line is in a comment
 
 
$new_reports = Get-ChildItem "C:\dfsreports\*.html" |
               Sort-Object -Property LastWriteTime -Descending |
               Select-Object -First 6
 
#
# Count reported errors and warnings in the generated html files
 
$warnerr = @()
 
# string array to hold all of the errors and warnings extracted from the report
$displaywarnerr = @()
# this is for email, not for calculations. If we need to send an email, show problematic shares
# this way, calculations aren't thrown off by numbers in file names
 
 
foreach($file in $new_reports)
{
 
"file:" + $file.name
# unnecessary debug line
$displaywarnerr += $file.name 
 
$healthreport = get-content $file
$mainline = $healthreport[385]
# line 385 of the html file has the relevent info
$errmsg=$mainline.IndexOf("Servers with DFS Replication errors")
$mainline.substring($errmsg,39)
# display dfs replication errors
# unnecessary debug line
 
$warnerr +=   $mainline.substring($errmsg,39)
$displaywarnerr +=   $mainline.substring($errmsg,39)                                                                                         
# grab error messages for calculating and perhaps in email
 
$warnmsg= $mainline.IndexOf("Servers with DFS Replication warnings")                                                                
$mainline.substring($warnmsg,41)
  
# display dfs replication warnings
#unnecessary debug line
$warnerr += $mainline.substring($warnmsg,41)
$displaywarnerr += $mainline.substring($warnmsg,41)
# add the warnings to the string arrays for calculations and perhaps in emails    
" "
$displaywarnerr += "`n"
 
$one = $warnerr | select-string (1)
$two = $warnerr | select-string (2)
$totalwarningserrors = ($one.length +  2* ($two.length))
  "Total Warnings and Errors: " + $totalwarningserrors              
  if ($totalwarningserrors -ge 1)
  # if at least 1 warning or error, send an alert email
  {
 
Send-MailMessage -to "my_company alerts <alerts@my_company.com>" -smtpserver my_exchange_server -from dfsr@my_company.com -subject "dfsr health report ($totalwarningserrors issues ) for $(get-date -format MMM/dd/yyyy) from $env:COMPUTERNAME" -body "DFSR Health Report for $(get-date -format MMM/dd/yyyy) from $env:COMPUTERNAME . Total number of issues reported: $totalwarningserrors `n Please view attachments in IE `n $displaywarnerr" -Attachments $new_reports ;
}
# sending mail messages require anonymous relay set up in the exchange server from the ip of the file server or
# authentication. Do as you please
 
 
# this part forward deals with conflicts and deleted
 
 
$today = get-date
$twodaysago=$today.adddays(-2)
# we are kooking for conflicts in the last 48 hours 
$conflictscount=0;
$displayconflicts = @()
# use displayconflicts for email in body
$conflicts= get-dfsrpreservedfiles -path D:\DFSRoots\my_companydata\DfsrPrivate\ConflictAndDeletedManifest.xml | select path, preservedtime  | where preservedtime -ge  $twodaysago ;
$displayconflicts +=  get-dfsrpreservedfiles -path D:\DFSRoots\my_companydata\DfsrPrivate\ConflictAndDeletedManifest.xml |  where preservedtime -ge  $twodaysago |  select path   | out-string -width 300 ;
foreach($line in $conflicts) {  $conflictscount++}
$displayconflicts
 
$conflicts= get-dfsrpreservedfiles -path D:\DFSRoots\marketing\DfsrPrivate\ConflictAndDeletedManifest.xml | select path, preservedtime  | where preservedtime -ge  $twodaysago ;
$displayconflicts += get-dfsrpreservedfiles -path D:\DFSRoots\marketing\DfsrPrivate\ConflictAndDeletedManifest.xml | where preservedtime -ge  $twodaysago |  select path   | out-string -width 300 ;
foreach($line in $conflicts) {  $conflictscount++}
$displayconflicts
$conflicts= get-dfsrpreservedfiles -path D:\DFSRoots\home\DfsrPrivate\ConflictAndDeletedManifest.xml | select path, preservedtime  | where preservedtime -ge  $twodaysago ;
$displayconflicts += get-dfsrpreservedfiles -path D:\DFSRoots\home\DfsrPrivate\ConflictAndDeletedManifest.xml | where preservedtime -ge  $twodaysago |  select path   | out-string -width 300 ;
 
$displayconflicts
 
foreach($line in $conflicts) {  $conflictscount++}
"Total number of conflicts: " + $conflictscount
if($conflictscount -ge 1)
#if at least one conflict or error, send an alert email
{
 
get-dfsrpreservedfiles -path D:\DFSRoots\my_companydata\DfsrPrivate\ConflictAndDeletedManifest.xml | select path, preservedtime  | where preservedtime -ge  $twodaysago | out-file my_companyconflict.txt -Width 300 ; " end of list" | out-file my_companyconflict.txt -append  ;
get-dfsrpreservedfiles -path D:\DFSRoots\marketing\DfsrPrivate\ConflictAndDeletedManifest.xml | select path, preservedtime  | where preservedtime -ge  $twodaysago | out-file marketingconflict.txt -Width 300 ; " end of list" | out-file marketingconflict.txt -append ;
get-dfsrpreservedfiles -path D:\DFSRoots\home\DfsrPrivate\ConflictAndDeletedManifest.xml      | select path, preservedtime  | where preservedtime -ge  $twodaysago | out-file homeconflict.txt -Width 300 ;  " end of list" | out-file homeconflict.txt -append ;
# prevents null files if no conflicts
 
$conflict_reports = Get-ChildItem "C:\dfsreports\" |
               Sort-Object -Property LastWriteTime -Descending |
               Select-Object -First 3
               Send-MailMessage -to "my_company alerts <alerts@my_company.com>"  -smtpserver my_exchange_server -from dfsr@my_company.com -subject " $env:COMPUTERNAME dfsr conflict report, total $conflictscount  for $(get-date -format MMM/dd/yyyy)   " -body "DFSR conflict report Attached for $(get-date -format MMM/dd/yyyy) from $env:COMPUTERNAME . `n $displayconflicts"  -Attachments $conflict_reports ;
$displayconflicts
}


BC AdBot (Login to Remove)

 


#2 JohnnyJammer

JohnnyJammer

  • Members
  • 1,117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:QLD Australia
  • Local time:05:48 AM

Posted 21 September 2015 - 06:48 PM

Looks good mate but a lot of code to get some stadard info using WMIC, below is a script to get similar info ina  nice HTMl page table.

@echo off
echo ***************************************************
echo * This will test the Sync Info for DFSR           *
echo * Script by JohnnyJammer                          *
echo ***************************************************
cd \
echo Executing command now..................
::Change the name of the servers to suite your needs.
wmic /output:C:\DFSRSyncinfo.html /node:server01,server02,server03 /namespace:\\root\microsoftdfs path dfsrsyncinfo get membername,replicationgroupname,bytestransferred,conflictsgenerated,inbound,updatesnottransferred,updatestobetransferred /format:htable.xsl
pause

Odviously you can use a different Path type using MSDN.



#3 Fardooste

Fardooste
  • Topic Starter

  • Members
  • 107 posts
  • OFFLINE
  •  
  • Local time:02:48 PM

Posted 22 September 2015 - 08:51 AM

The added code is to get over the shortcomings of the basic code, which generates reports that need to be manually looked through.

This is the basic code:

Write-DfsrHealthReport -GroupName "RG01" -ReferenceComputerName "SRV01" -MemberComputerName "SRV02" -Path "C:\reports" -CountFiles






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users