Active Directory replication health powershell
Runs `repadmin /replsummary` on a domain controller and parses the per-source failure counts. Posts total failure count + the failing summary lines. Schedule on at least one DC per site.
Placeholders only. Before running, replace
YOUR_URL with your capture endpoint's POST URL
.
(Open this page from your capture object to have these auto-filled.)
# ad-replication.ps1 — domain controller replication summary via repadmin.
# Run on a DC (or any host with RSAT-AD installed).
$Url = "YOUR_URL/ad-repl"
$Output = & repadmin /replsummary 2>&1
$ExitCode = $LASTEXITCODE
if ($ExitCode -ne 0) {
$Body = (@{
hostname = $env:COMPUTERNAME
error = "repadmin exit $ExitCode"
output_excerpt = ($Output | Select-Object -First 20) -join "`n"
}) | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $Url -Method Post -Body $Body -ContentType "application/json" -TimeoutSec 15 | Out-Null
exit 1
}
$Failures = 0
$FailingLines = @()
# repadmin /replsummary rows look like:
# Source DSA largest delta fails/total %% error
# DC01 00m:01s 0/ 6 0
foreach ($line in $Output) {
if ($line -match '^\s*\S+\s+\S+\s+(\d+)\s*/\s*\d+\s+\S+') {
$fails = [int]$matches[1]
if ($fails -gt 0) {
$Failures += $fails
$FailingLines += $line.Trim()
}
}
}
$Body = (@{
hostname = $env:COMPUTERNAME
total_failures = $Failures
failing_summary = $FailingLines
}) | ConvertTo-Json -Compress -Depth 4
Invoke-RestMethod -Uri $Url -Method Post -Body $Body `
-ContentType "application/json" -TimeoutSec 15 | Out-Null
Recommended pairing
Add a capture.value check to this capture object.
json_path = total_failures, op = >, threshold = 0 (severity: crit — any failing replica is bad).
What is the filename?
ad-replication.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com