best business builder

Active Directory Replication Summary to your Email

Active Directory replication is a critical process that ensures the consistent and up-to-date state of directory information across all domain controllers in a domain. Monitoring this process is important as it helps identify any issues that may arise and resolve them quickly. One way to monitor Active Directory replication is by using the Repadmin command-line tool. Repadmin provides a wealth of information about the replication status and health of a domain. However, manually checking the Repadmin output can be time-consuming and tedious, and running it manually every 30 minutes just to check if everything is great doesn’t seem like a great idea. While PowerShell has its own commands around replication I’ve not found something as fast and reliable as repadmin /replsummary.

Replication Summary to an email

So, as part of my advanced Active Directory module called ADEssentials, I wrote a function that uses repadmin to generate results. Then, I use PSWriteHTML to process them and Mailozaurr to send them to my email. Here’s a how I did it:

$ReplicationSummary = Get-WinADForestReplicationSummary -IncludeStatisticsVariable Statistics

$Body = EmailBody {
EmailImage -Source 'https://companywebsite.xyz/wp-content/uploads/2021/04/Logo-evotec-bb.png' -UrlLink '' -AlternativeText 'Logo' -Width 181 -Heigh 57 -Inline

EmailText -Text "Dear ", "AD Team," -LineBreak
EmailText -Text "Upon reviewing the resuls of replication I've found: "
EmailList {
EmailListItem -Text "Servers with good replication: ", $($Statistics.Good) -Color Black, SpringGreen -FontWeight normal, bold
EmailListItem -Text "Servers with replication failures: ", $($Statistics.Failures) -Color Black, Red -FontWeight normal, bold
EmailListItem -Text "Servers with replication delta over 24 hours: ", $($Statistics.DeltaOver24Hours) -Color Black, Red -FontWeight normal, bold
EmailListItem -Text "Servers with replication delta over 12 hours: ", $($Statistics.DeltaOver12Hours) -Color Black, Red -FontWeight normal, bold
EmailListItem -Text "Servers with replication delta over 6 hours: ", $($Statistics.DeltaOver6Hours) -Color Black, Red -FontWeight normal, bold
EmailListItem -Text "Servers with replication delta over 3 hours: ", $($Statistics.DeltaOver3Hours) -Color Black, Red -FontWeight normal, bold
EmailListItem -Text "Servers with replication delta over 1 hour: ", $($Statistics.DeltaOver1Hours) -Color Black, Red -FontWeight normal, bold
EmailListItem -Text "Unique replication errors: ", $($Statistics.UniqueErrors.Count) -Color Black, Red -FontWeight normal, bold
}

if ($Statistics.UniqueErrors.Count -gt 0) {
EmailText -Text "Unique replication errors:"
EmailList {
foreach ($ErrorText in $Statistics.UniqueErrors) {
EmailListItem -Text $ErrorText
}
}
} else {
EmailText -Text "It seems you're doing a great job! Keep it up! 😊" -LineBreak
}

EmailText -Text "For more details please check the table below:"

EmailTable -DataTable $ReplicationSummary {
EmailTableCondition -Inline -Name "Fail" -HighlightHeaders 'Fails', 'Total', 'PercentageError' -ComparisonType number -Operator gt 0 -BackgroundColor Salmon -FailBackgroundColor SpringGreen
} -HideFooter

EmailText -LineBreak
EmailText -Text "Kind regards,"
EmailText -Text "Your automation friend"
}


$EmailSplat = @{
From = 'admin@company.com'
To = 'users@company.com'
Body = $Body
Priority = if ($Statistics.Failures -gt 0) { 'High' } else { 'Low' }
Subject="Replication Results 💖"
Verbose = $true
WhatIf = $false
MgGraph = $true
}

Connect-MgGraph
Send-EmailMessage @EmailSplat

What is the result of those 50 lines of code?

The Get-WinADForestReplicationSummary function joins over 100 functions available for Active Directory admins in the ADEssentials module. It’s doing the heavy lifting of reading repadmin data and converting it to PowerShell objects. Then, we use the PSWriteHTML EmailBody function, which allows for the accessible building of emails without knowing HTML and CSS. Finally, since I wanted to send an email with Microsoft Graph, I’ve used Mailozaurr’s amazing Send-EmailMessage to send an email.


Got a project that needs expert IT support?

From Linux and Microsoft Server to VMware, networking, and more, our team at CR Tech is here to help.

Get personalized support today and ensure your systems are running at peak performance or make sure that your project turns out to be a successful one!

CONTACT US NOW
best vpn deal