Sunday, 3 September 2023

Monitoring Active Directory (AD) replication status and receiving email alerts

Monitoring Active Directory (AD) replication status and receiving email alerts




# Define the recipient email address and SMTP server settings

$RecipientEmail = "recipient@email.com"

$SMTPServer = "smtp.example.com"

$SMTPPort = 587

$SMTPUsername = "yourusername"

$SMTPPassword = "yourpassword"

 

# Run Repadmin to check replication status

$RepadminOutput = Invoke-Expression -Command "repadmin /showrepl"

 

# Check if Repadmin output contains any errors


if ($RepadminOutput -match "Error") {

    # Send an email alert

    Send-MailMessage -From "your@email.com" -To $RecipientEmail -Subject "AD Replication Error Alert" -SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -Credential (Get-Credential -UserName $SMTPUsername -Password $SMTPPassword) -Body "AD replication error detected:`r`n$RepadminOutput"

}

No comments:

Post a Comment