[ Team LiB ] Previous Section Next Section

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

Property

Description

IsDeletedSourceDsa

Boolean indicating whether the source DC has been deleted.

LastSyncResult

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

NamingContextDN

DN of the Naming Context for which the partners replicate.

NumConsecutiveSyncFailures

Number of consecutive sync failures between the two neighbors.

SourceDsaCN

CN of the replication neighbor.

SourceDsaSite

Site the replication neighbor is in.

TimeOfLastSyncAttempt

Time of the last sync attempt.

TimeOfLastSyncSuccess

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 & _
                       "\root\MicrosoftActiveDirectory")
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"
      else
         wscript.echo " " & objProp.Name & " : " & objProp.Value
      end if 
   next
   
   Wscript.echo ""
next

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

Property

Description

DsaDN

DN of replication neighbor.

NamingContextDN

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

PositionInQ

Number representing the position in the replication queue.

TimeEnqueued

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 & _
                       "\root\MicrosoftActiveDirectory")
Set objRepOps = objWMI.ExecQuery("Select * from MSAD_ReplPendingOp")
   
if objRepOps.Count = 0 then
    Wscript.Echo "There are no pending replication operations"
else
    for each objRepOp in objRepOps
        Wscript.Echo objRepOp.DsaDN
        Wscript.Echo objRepOp.NamingContextDN
        Wscript.Echo objRepOp.PositionInQ
        Wscript.Echo objRepOp.TimeEnqueued
    next
end if
    [ Team LiB ] Previous Section Next Section