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

How To Hide Featured Image in Blog Posts in Single View

In WordPress, single posts can have a featured image to help with displaying in List…

Resolve Error: (59) An unexpected network error occurred

Prerequisites:   Ensure the the target machine has PowerShell Remoting Enabled (as it's Disabled by…

Basic CSS: Use Clockwise Notation to Specify the Padding of an Element

<style>.injected-text {margin-bottom: -25px;text-align: center;}.box {border-style: solid;border-color: black;border-width: 5px;text-align: center;}.yellow-box {background-color: yellow;padding: 20px 40px 20px 40px;}.red-box…