Wednesday, December 17, 2008

Monitor Active Directory Replication

Returns a list of pending replication jobs on a domain controller

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\MicrosoftActiveDirectory")
Set colReplicationOperations = objWMIService.ExecQuery _
        ("Select * from MSAD_ReplPendingOp")
If colReplicationOperations.Count = 0 Then
    Wscript.Echo "There are no replication jobs pending."
    Wscript.Quit
Else
    For each objReplicationJob in colReplicationOperations 
        Wscript.Echo "Serial number: " & objReplicationJob.SerialNumber
        Wscript.Echo "Time in queue: " & objReplicationJob.TimeEnqueued
        Wscript.Echo "DSA DN: " & objReplicationJob.DsaDN
        Wscript.Echo "DSA address: " & objReplicationJob.DsaAddress
        Wscript.Echo "Naming context DN: " & objReplicationJob.NamingContextDn
    Next
End If

This is a VB Script, this can be used by saving the file in .vbs file