26.9 Monitoring Replication

The WMI Replication provider is another good example of how Microsoft is leveraging WMI to help with monitoring Active Directory. Like the Trustmon provider, the Replication provider is only available with Windows Server 2003 and is contained under the root\MicrosoftActiveDirectory namespace. It provides classes to list the replication partners for a domain controller, view the supported Naming Contexts for a domain controller, and also see the pending replication operations.

As of the time of this writing, Microsoft had not published any documentation on the Replication provider. Most of the information contained in this section was observed by one of the authors and is likely not to be the complete story!

Table 26-8 contains some of the more useful properties for the MSAD_ReplNeighbor class, which represents a replication partner (or neighbor) for a given domain controller.

Table 26-8. Useful MSAD_ReplNeighbor properties




Boolean indicating whether the source DC has been deleted.


Number representing the result of the last sync operation with this neighbor. A value of 0 indicates success.


DN of the Naming Context for which the partners replicate.


Number of consecutive sync failures between the two neighbors.


CN of the replication neighbor.


Site the replication neighbor is in.


Time of the last sync attempt.


Time of last successful sync attempt.

There are actually several property methods available other than what is shown in Table 26-8, so in the following example, we will enumerate all the replication neighbors and print out every property available to the MSAD_ReplNeighbor class.

strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & _
Set objReplNeighbors = objWMI.ExecQuery("Select * from MSAD_ReplNeighbor")
for each objReplNeighbor in objReplNeighbors
   Wscript.Echo objReplNeighbor.SourceDsaCN & "/" & _
                objReplNeighbor.NamingContextDN & ":"
   for each objProp in objReplNeighbor.Properties_
      if IsNull(objProp.Value) then
         Wscript.Echo " " & objProp.Name & " : NULL"
         wscript.echo " " & objProp.Name & " : " & objProp.Value
      end if 
   Wscript.echo ""

Now that we can find all of the replication neighbors for a given domain controller, we will take a look at any outstanding replication operations. The MSAD_ReplPendingOp class represents a pending replication operation. The class has several property methods, and some of the more useful ones are listed in Table 26-9.

Table 26-9. Useful MSAD_ReplPendingOp properties




DN of replication neighbor.


DN of Naming Context that holds the object being sync'd.


Number representing the position in the replication queue.


Date representing when operation was put in the queue.

The next example is not much different from most of our others. We simply query all MSAD_ReplPendingOp objects for a particular host. If zero are returned, that signifies there are no pending replication operations on the host.

strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & _
Set objRepOps = objWMI.ExecQuery("Select * from MSAD_ReplPendingOp")
if objRepOps.Count = 0 then
    Wscript.Echo "There are no pending replication operations"
    for each objRepOp in objRepOps
        Wscript.Echo objRepOp.DsaDN
        Wscript.Echo objRepOp.NamingContextDN
        Wscript.Echo objRepOp.PositionInQ
        Wscript.Echo objRepOp.TimeEnqueued
end if

    Part II: Designing an Active Directory Infrastructure
    Part III: Scripting Active Directory with ADSI, ADO, and WMI