Posted On March 11, 2020

PowerShell: Get Active Directory Domain Controller Replication Status

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Get Active Directory Domain Controller Replication Status
$domaincontroller=(Get-ADForest |Select-Object -ExpandProperty RootDomain |Get-ADDomain |Select-Object -Property PDCEmulator).PDCEmulator;

## Define Objects ##

$report = New-Object PSObject -Property @{

ReplicationPartners = $null

LastReplication = $null

FailureCount = $null

FailureType = $null

FirstFailure = $null

}

## Replication Partners ##

$report.ReplicationPartners = (Get-ADReplicationPartnerMetadata -Target $domaincontroller).Partner

$report.LastReplication = (Get-ADReplicationPartnerMetadata -Target $domaincontroller).LastReplicationSuccess

## Replication Failures ##

$report.FailureCount  = (Get-ADReplicationFailure -Target $domaincontroller).FailureCount

$report.FailureType = (Get-ADReplicationFailure -Target $domaincontroller).FailureType

$report.FirstFailure = (Get-ADReplicationFailure -Target $domaincontroller).FirstFailureTime

## Format Output ##

$report | select ReplicationPartners,LastReplication,FirstFailure,FailureCount,FailureType | Out-GridView

<#
Active Directory or SysVol is inaccessible on this domain controller or an object is missing.
dc1.kimconnect.com inaccessible, site name: Default-First-Site-Name, IP address: 192.1000.5154.1544, GPOs: data uncollected

The issue was solved as below:
1. Backup GPOs from PDC and import them on other three DCs
2. Reset to default permissions on all GPOs
3. delete some registry.tmp file from some policies (this file exists in some GPOs -in sysvol- on one or two DCs and do not exist on other DCs)
#>

$ReplicaDirectoryServers=(Get-ADForest |Select-Object -ExpandProperty RootDomain |Get-ADDomain|select ReplicaDirectoryServers).ReplicaDirectoryServers
$pdc=(Get-ADForest |Select-Object -ExpandProperty RootDomain |Get-ADDomain |Select-Object -Property PDCEmulator).PDCEmulator;
$bdc=$ReplicaDirectoryServers[0];
$pdcSysvolSubFolders=Get-ChildItem -path "\\$pdc\c$\Windows\SYSVOL\domain\Policies"|sort -property LastWriteTime -Descending
$bdcSysvolSubFolders=Get-ChildItem -path "\\$bdc\c$\Windows\SYSVOL\domain\Policies"|sort -property LastWriteTime -Descending

for ($i=0;$i -lt $pdcSysvolSubFolders.count; $i++){
    Compare-Object -ReferenceObject $pdcSysvolSubFolders[$i] -DifferenceObject $bdcSysvolSubFolders[$i]
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

IIS Error Code 0x80070021

Error Message: Detailed Error Information:Module IIS Web CoreNotification BeginRequestHandler Not yet determinedError Code 0x80070021Config Error…

Quick Snippet to Copy NTFS Permissions Between SMB Shares

The experimental script below will sync permissions of a folder toward another.WARNING: if sub-folders at…

PowerShell: Purge User Outlook Profile

# Purge-User-Outlook-Profile.ps1# Set folder path$folderToDelete="$env:localappdata\Microsoft\Outlook";function purgeFolder($path){ mkdir c:\temp -force -ea SilentlyContinue | out-null cd c:\temp…