This blog will give the solution and fix for Active Directory and Messaging administrators

  • A directory is a hierarchical structure that stores information about objects on the network. Active Directory Domain Services (AD DS), stores information about objects on the network like user accounts, such as names, passwords, phone numbers, and so on, and enables other authorized users on the same network to access this information. Active Directory uses a structured data store as the basis for a logical, hierarchical organization of directory information.

  • Microsoft 365 is a cloud-based services designed to help meet your organization's needs for robust security, reliability, and user productivity.

  • Microsoft Learning

    Learn technical skills with Microsoft role based certifications, find the right training and certification opportunities to aid in your career growth and success.

  • Microsoft Exchange Online is a hosted messaging solution that delivers the capabilities of Microsoft Exchange Server as a cloud-based service. It gives users access to email, calendar, contacts, and tasks from PCs, the web, and mobile devices. It integrates fully with Active Directory, enabling administrators to use group policies, as well as other administration tools, to manage Exchange Online features across their environment

  • Powershell

    A comprehensive command line interface and scripting language for Windows. Introduced in 2006, PowerShell is a major upgrade from the Windows command line, which uses DOS commands. PowerShell supports common programming structures such as "if-then-else" and "while," it is generally less complicated than Microsoft's VBScript and JScript languages.

Active Directory Replication Monitoring Powershell Script

This script generate AD replication report and send the email to the specified email ID as below. Please change the email notification settings


#===================================================================#

# This Script (v1.0) is to monitor the Active Directory Replication #

# Created on 29-05-2023 by Ezhilkumar                               #

#===================================================================#


$a = repadmin /showrepl * /csv

$a | Out-File -FilePath "D:\Scripts\AD_ReplicationMonitor\ADReplicationreport.csv" -Encoding UTF8

$b = ConvertFrom-Csv -InputObject $a | Where-Object {($_.'number of failures' -ge "1") -or ($_.'Naming Context' -like "*server down*")}

if ($b -ne $null) {

    $c = "Hi Team, `nThere are replication failures in Test.com. Please check the replication report and take necessary action immediately.`n`n"

    $c += "<h2 style='color: #ff0000;'>Test.com Active Directory Replication Status: There are replication failures</h2>"

    $c += "<table style='border-collapse: collapse; width: 100%; font-size: 12px;'>"

    $c += "<colgroup><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'></colgroup>"

    $c += "<tr><th colspan='10' style='background-color: #0000ff; border: 1px solid #dddddd; padding: 8px;'>Test.com Active Directory Replication Status</th></tr>"

    $c += "<tr><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Destination DSA Site</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Destination DSA</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Naming Context</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Source DSA Site</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Source DSA</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Transport Type</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Number of Failures</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Last Failure Time</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Last Success Time</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Last Failure Status</th></tr>"

    foreach ($entry in $b) {

        $failureCount = $entry.'number of failures'

        $c += "<tr"

        if ($failureCount -ge "1") {

            $c += " style='background-color: #ff0000;'"

        }

        $c += ">"

        $c += "<td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Destination DSA Site')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Destination DSA')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Naming Context')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Source DSA Site')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Source DSA')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Transport Type')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Number of Failures')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Last Failure Time')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Last Success Time')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Last Failure Status')</td></tr>"

    }

    $c += "</table>"

} else {

    $c = "Hi Team, `nAD replication is fine in Test.com domain, and there were no replication failures.`n`n"

    $c += "<h2 style='color: #008000;'>Test.com Active Directory Replication Status: Success</h2>"

    $c += "<table style='border-collapse: collapse; width: 100%; font-size: 12px;'>"

    $c += "<colgroup><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'><col style='width: auto;'></colgroup>"

    $c += "<tr><th colspan='10' style='background-color: #0000ff; border: 1px solid #dddddd; padding: 8px;'>Test.com Active Directory Replication Status</th></tr>"

    $c += "<tr><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Destination DSA Site</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Destination DSA</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Naming Context</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Source DSA Site</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Source DSA</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Transport Type</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Number of Failures</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Last Failure Time</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Last Success Time</th><th style='background-color: #f1f1f1; border: 1px solid #dddddd; padding: 8px;'>Last Failure Status</th></tr>"

    $csvData = Import-Csv -Path "D:\Scripts\AD_ReplicationMonitor\ADReplicationreport.csv"

    foreach ($entry in $csvData) {

        $c += "<tr><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Destination DSA Site')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Destination DSA')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Naming Context')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Source DSA Site')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Source DSA')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Transport Type')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Number of Failures')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Last Failure Time')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Last Success Time')</td><td style='border: 1px solid #dddddd; padding: 8px;'>$($entry.'Last Failure Status')</td></tr>"

    }

    $c += "</table>"

}

# Email notification settings

$sender = "Noreply_ADReplicationReport@test.com"

$recipients = "recipients@test.com"

$ccrecipients = "recipients@test.com"

$subject = "Test.com Active Directory Replication Status"

$body = "<html><body>$c</body></html>"

$attachmentPath = "D:\Scripts\AD_ReplicationMonitor\ADReplicationreport.csv"

$mailParams = @{

    From = $sender

    To = $recipients

    Cc = $ccrecipients

    Subject = $subject

    Body = $body

    BodyAsHtml = $true

    SmtpServer = "mail.Test.com"

    Attachments = $attachmentPath

}

# Send the email

Send-MailMessage @mailParams


Share:

Search This Blog

Recent Posts