Check Active Directory partition replication remotly with PowerShell

Hello,

Do you ever need to check Active Directory partition replication without log in on every DC to run “RepAdmin /ShowRepl” ?

I wrote a simple but nice function :

Function Get-ADPartitionReplicationInfo {
    <#
    .SYNOPSIS
        This cmdlet get Active Directory replication information between two Domain Controllers.
    .DESCRIPTION
        This cmdlet uses WMI class : MSAD_ReplNeighbor.
    .PARAMETER DestDC
        This is DC that will be query by WMI to retrieve informations.
    .PARAMETER SourceDC
        This is the DC name that we want informations about.
    .EXAMPLE
        Get-ADPartitionReplicationInfo -SourceDC DC1 -DestDC DC2
    .LINK
        http://ItForDummies.net
    #>
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$false,
            HelpMessage='Provide source DC.')]
        [ValidateScript({Test-Connection -Quiet -Count 1 -ComputerName $_})]
        [String]$SourceDC='%',
        [Parameter(Mandatory=$false,
            HelpMessage='Provide destination DC.')]
        [ValidateScript({Test-Connection -Quiet -Count 1 -ComputerName $_})]
        [String]$DestDC=$env:COMPUTERNAME
    )
    Begin{}
    Process{
        try{
            Write-Verbose -Message "Trying connecting $DestDC with WMI..."
            Get-WmiObject -Namespace rootMicrosoftActiveDirectory `
                -class MSAD_ReplNeighbor `
                -ComputerName $DestDC `
                -filter "sourceDsaCN like'$SourceDC'" `
                -property TimeOfLastSyncSuccess, NamingContextDN, LastSyncResult, sourceDsaCN |
                    Select-Object NamingContextDN,LastSyncResult,@{Label="TimeOfLastSuccess";Expression={[System.Management.ManagementDateTimeConverter]::ToDateTime($_.TimeOfLastSyncSuccess)}},sourceDsaCN
        }
        catch{Write-Warning -Message "$DestDC : $_"}
    }
    End{}
}

You can use “Get-Help” on it :

Get-Help Get-ADPartitionReplicationInfo -Full

I also posted it on TechNet.

Leave a Reply