# ============================================================================================== 
# NAME: Check-Replication 
#  
# AUTHOR: Alberto Igbinedion
# DATE  : 24/04/2015/04/2015 
#  
# COMMENT: Will check the replication status and if there are failures will send an email to the 
# Assigned Addresses. 
# ** Requires Repadmin from the Windows resource Kit accessible in the default path ** 
# ============================================================================================== 

#Set email address variable  
$from = "Replication Status alberto.igbinedion@controlsdata.com"
$to = "alberto.igbinedion@controlsdata.com" 

#Collect the replication info  
#Check the Replication with Repadmin 
$workfile = repadmin /showrepl * /csv  
$results = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1} 
  
  
#Here you set the tolerance level for the report 
$results = $results | where {$_.'Number of Failures' -gt 1 } 

$msg =  " There were no Replication Errors. " 
 
if ($results -ne $null ) { 
    $results = $results  | select "Source DC", "Naming Context", "Destination DC" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-Html 
    } 
	else { 
    $results =  "$msg"
} 

#Send-MailMessage of replication status   
Send-MailMessage -From $from -To $to -Subject "AECUK Daily DC Replication Status" -SmtpServer "AEC01A-HC01.aecuk.aec.local" -BodyAsHtml ($results | Out-String) 