Skip to content

Instantly share code, notes, and snippets.

@junecastillote
Last active March 1, 2023 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junecastillote/701049e87615fbacf10e5f97093a7a73 to your computer and use it in GitHub Desktop.
Save junecastillote/701049e87615fbacf10e5f97093a7a73 to your computer and use it in GitHub Desktop.
Active Directory Replication Health

Example 1: Display the result on the screen

.\Invoke-ADReplicationReport.ps1

This example gets the replication status of the local computer and all of its replication partners.

.\Invoke-ADReplicationReport.ps1 -Server <DC1>

This example gets the replication status of the specified DC and all of its partners.

.\Invoke-ADReplicationReport.ps1 -Server *

This example gets the replication status of all DCs and all of their replication partners.

Example 2: Send the report via email

# define the email parameters
$emailReport = @{
    SmtpServer = 'mail.theitbros.com'
    From = 'monitoring@theitbros.com'
    To = 'alpha@theitbros.com'
    Subject = 'Active Directory Replication Health'
    BodyAsHTML = $true
}

# Generate the report and send via email
.\Invoke-ADReplicationReport.ps1 -Server * -EmailReport $emailReport
[cmdletbinding()]
param (
[parameter()]
[string]
$Server,
[Parameter()]
[hashtable]
$EmailReport
)
# If no Server is specified, will use the local computer.
if (-not($Server)) {
$Server = $env:COMPUTERNAME
}
$replStatus = $(
repadmin /showrepl $Server /csv | ConvertFrom-Csv | Select-Object `
@{n = 'From'; e = { "$($_.'Source DSA Site')\$($_.'Source DSA')" } },
@{n = 'To'; e = { "$($_.'Destination DSA Site')\$($_.'Destination DSA')" } },
@{n = 'Partition'; e = { "$($_.'Naming Context')" } },
@{n = 'FailureCount'; e = { "$($_.'Number of Failures')" } },
@{n = 'LastFailureStatus'; e = { "$($_.'Last Failure Status')" } },
@{n = 'LastFailureTime'; e = { "$($_.'Last Failure Time')" } },
@{n = 'LastSuccessTime'; e = { "$($_.'Last Success Time')" } }
)
if (-not($EmailReport)) {
return $replStatus
}
$head = @'
<style>
h1 {
font-family: "Arial Black", arial, sans-serif;
}
table {
font-family: Consolas, Tahoma, arial, sans-serif;
border-collapse: collapse;
/* width: 100%; */
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
'@
$htmlSplat = @{
Title = 'Active Directory Replication Health'
PreContent = "<H1>Active Directory Replication Health</H1><p>"
Head = $head
}
Send-MailMessage @EmailReport -Body $(($replStatus | ConvertTo-Html @htmlSplat) -join "`n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment