21 February, 2022

Domain Controller Sync partner, force sync and show results

I ran into some annoyances related to it taking more time than my patience was allowing, for all of our domain controllers to be in sync... 

Because, while I am connected to a DC in the mid-West, making changes, it can take up to 15 minutes for those changes to be reflected with the DC's on the East coast... 






Adding in an Azure DC, and o365 to that, just shortens my patience even more, when I need to move things along...

Plus, if I suspect there may be sync issues, I needed a quick way to know / rule that out.

This script does a line by line replication with each respective DC sync partner - And reports that result.

Then it confirms the partner sync status.

I set the confirmation bit as a function, so that it can also easily be run by itself.

$SyncMeta = @()
Write-Host "Gathering DC sync partner list..." -Fore 14
$All_DCs_Sync = (Get-ADDomainController -Filter * | sort).Hostname | % {($_).Split('.')[0]} | % {
$Server_ = $_
$SyncMeta += Get-ADReplicationPartnerMetadata -Target $Server_ | select @{n='Server';e={$Server_}}, @{n='Partner';e={($_.Partner).Split(',')[1].Split('=')[1]}}
}
$DomPart = (Get-ADDomainController).DefaultPartition
$SyncMeta | % {
$SyncResult = Repadmin /replicate $_.Partner $_.Server $DomPart
Write-Host "  $(($SyncResult | Out-String).Trim())" -Fore 11
}

##################################

Function SyncReport {
''
Write-Host "Start sync query : " -Fore 14 -No
Get-Date -Format "MM/d/yyyy hh:mm:ss tt"

$All_DCs_Sync = (Get-ADDomainController -Filter * | sort).Hostname | % {($_).Split('.')[0]} | % {
$Server_ = $_
Get-ADReplicationPartnerMetadata -Target $Server_ | select @{n='Server';e={$Server_}}, @{n='Partner';e={($_.Partner).Split(',')[1].Split('=')[1]}}, LastReplicationAttempt, LastReplicationSuccess
}
Write-Host "Finish sync query: " -Fore 14 -No
Get-Date -Format "MM/d/yyyy hh:mm:ss tt"
''
Write-Host (($All_DCs_Sync | sort -Descending  LastReplicationSuccess | Out-String)).Trim()
''
$Newest_Sync = ($All_DCs_Sync.LastReplicationSuccess | sort -Descending)[0]
$Oldest_Sync = ($All_DCs_Sync.LastReplicationSuccess | sort -Descending)[-1]
Write-Host "Time between MOST recent, and LEAST recent:" -Fore 11
(($Newest_Sync - $Oldest_Sync) | Select Days, Hours, Minutes, Seconds | fl | Out-String).Trim()
}

SyncReport

No comments:

Post a Comment