{"id":3522,"date":"2025-03-13T15:19:51","date_gmt":"2025-03-13T20:19:51","guid":{"rendered":"https:\/\/microsoftgeek.com\/?p=3522"},"modified":"2025-03-13T15:21:38","modified_gmt":"2025-03-13T20:21:38","slug":"active-directory-replication-summary-to-your-email","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=3522","title":{"rendered":"Active Directory Replication Summary to your Email"},"content":{"rendered":"\n<p><strong>Active Directory replication<\/strong>&nbsp;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&nbsp;<strong>Active Directory<\/strong>&nbsp;replication is by using the Repadmin command-line tool.&nbsp;<strong>Repadmin<\/strong>&nbsp;provides a wealth of information about the replication status and health of a domain. However, manually checking the&nbsp;<strong>Repadmin<\/strong>&nbsp;output can be time-consuming and tedious, and running it manually every 30 minutes just to check if everything is great doesn&#8217;t seem like a great idea. While&nbsp;<strong>PowerShell<\/strong>&nbsp;has its own commands around replication I&#8217;ve not found something as fast and reliable as&nbsp;<strong>repadmin \/replsummary<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Replication Summary to an email<\/h3>\n\n\n\n<p>So, as part of my advanced\u00a0<strong>Active Directory<\/strong>\u00a0module called\u00a0<a href=\"https:\/\/github.com\/EvotecIT\/ADEssentials\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>ADEssentials<\/strong><\/a>, I wrote a function that uses repadmin to generate results. Then, I use\u00a0<a href=\"https:\/\/github.com\/EvotecIT\/PSWriteHTML\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>PSWriteHTML<\/strong>\u00a0<\/a>to process them and\u00a0<strong>Mailozaurr<\/strong>\u00a0to send them to my email. Here&#8217;s a how I did it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ReplicationSummary = Get-WinADForestReplicationSummary -IncludeStatisticsVariable Statistics<br><br>$Body = EmailBody {<br>    EmailImage -Source 'https:\/\/companywebsite.xyz\/wp-content\/uploads\/2021\/04\/Logo-evotec-bb.png' -UrlLink '' -AlternativeText 'Logo' -Width 181 -Heigh 57 -Inline<br><br>    EmailText -Text \"Dear \", \"AD Team,\" -LineBreak<br>    EmailText -Text \"Upon reviewing the resuls of replication I've found: \"<br>    EmailList {<br>        EmailListItem -Text \"Servers with good replication: \", $($Statistics.Good) -Color Black, SpringGreen -FontWeight normal, bold<br>        EmailListItem -Text \"Servers with replication failures: \", $($Statistics.Failures) -Color Black, Red -FontWeight normal, bold<br>        EmailListItem -Text \"Servers with replication delta over 24 hours: \", $($Statistics.DeltaOver24Hours) -Color Black, Red -FontWeight normal, bold<br>        EmailListItem -Text \"Servers with replication delta over 12 hours: \", $($Statistics.DeltaOver12Hours) -Color Black, Red -FontWeight normal, bold<br>        EmailListItem -Text \"Servers with replication delta over 6 hours: \", $($Statistics.DeltaOver6Hours) -Color Black, Red -FontWeight normal, bold<br>        EmailListItem -Text \"Servers with replication delta over 3 hours: \", $($Statistics.DeltaOver3Hours) -Color Black, Red -FontWeight normal, bold<br>        EmailListItem -Text \"Servers with replication delta over 1 hour: \", $($Statistics.DeltaOver1Hours) -Color Black, Red -FontWeight normal, bold<br>        EmailListItem -Text \"Unique replication errors: \", $($Statistics.UniqueErrors.Count) -Color Black, Red -FontWeight normal, bold<br>    }<br><br>    if ($Statistics.UniqueErrors.Count -gt 0) {<br>        EmailText -Text \"Unique replication errors:\"<br>        EmailList {<br>            foreach ($ErrorText in $Statistics.UniqueErrors) {<br>                EmailListItem -Text $ErrorText<br>            }<br>        }<br>    } else {<br>        EmailText -Text \"It seems you're doing a great job! Keep it up! &#x1f60a;\" -LineBreak<br>    }<br><br>    EmailText -Text \"For more details please check the table below:\"<br><br>    EmailTable -DataTable $ReplicationSummary {<br>        EmailTableCondition -Inline -Name \"Fail\" -HighlightHeaders 'Fails', 'Total', 'PercentageError' -ComparisonType number -Operator gt 0 -BackgroundColor Salmon -FailBackgroundColor SpringGreen<br>    } -HideFooter<br><br>    EmailText -LineBreak<br>    EmailText -Text \"Kind regards,\"<br>    EmailText -Text \"Your automation friend\"<br>}<br><br><br>$EmailSplat = @{<br>    From           = 'admin@company.com'<br>    To             = 'users@company.com'<br>    Body           = $Body<br>    Priority       = if ($Statistics.Failures -gt 0) { 'High' } else { 'Low' }<br>    Subject        = 'Replication Results &#x1f496;'<br>    Verbose        = $true<br>    WhatIf         = $false<br>    MgGraph        = $true<br>}<br><br>Connect-MgGraph<br>Send-EmailMessage @EmailSplat<\/pre>\n\n\n\n<p>What is the result of those 50 lines of code?<\/p>\n\n\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/microsoftgeek.com\/wp-content\/uploads\/2025\/03\/AD.png\"><img loading=\"lazy\" decoding=\"async\" width=\"927\" height=\"679\" src=\"https:\/\/microsoftgeek.com\/wp-content\/uploads\/2025\/03\/AD.png\" alt=\"\" class=\"wp-image-3524\" srcset=\"https:\/\/microsoftgeek.com\/wp-content\/uploads\/2025\/03\/AD.png 927w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2025\/03\/AD-300x220.png 300w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2025\/03\/AD-768x563.png 768w\" sizes=\"auto, (max-width: 927px) 100vw, 927px\" \/><\/a><\/figure>\n\n\n\n<p id=\"bsdSZZj\"><a href=\"https:\/\/evotec.xyz\/wp-content\/uploads\/2024\/04\/img_662014103d259.png\"><\/a><\/p>\n\n\n\n<p>The\u00a0<strong>Get-WinADForestReplicationSummary<\/strong>\u00a0function joins over 100 functions available for\u00a0<strong>Active Directory<\/strong>\u00a0admins in the\u00a0<a href=\"https:\/\/github.com\/EvotecIT\/ADEssentials\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>ADEssentials<\/strong><\/a>\u00a0module. It&#8217;s doing the heavy lifting of reading repadmin data and converting it to PowerShell objects. Then, we use the PSWriteHTML\u00a0<strong>EmailBody<\/strong>\u00a0function, which allows for the accessible building of emails without knowing\u00a0<strong>HTML<\/strong>\u00a0and\u00a0<strong>CSS<\/strong>. Finally, since I wanted to send an email with\u00a0<strong>Microsoft Graph<\/strong>, I&#8217;ve used\u00a0<strong>Mailozaurr&#8217;s<\/strong>\u00a0amazing\u00a0<strong>Send-EmailMessage<\/strong>\u00a0to send an email.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Active Directory replication&nbsp;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&nbsp;Active Directory&nbsp;replication is by using the Repadmin command-line tool.&nbsp;Repadmin&nbsp;provides a wealth [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,59],"tags":[],"class_list":["post-3522","post","type-post","status-publish","format-standard","hentry","category-ad","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3522"}],"version-history":[{"count":4,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3522\/revisions"}],"predecessor-version":[{"id":3528,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3522\/revisions\/3528"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}