Do you have a scripting-related question or problem? You can send your question or problem to winscriptsol@winnetmag.com.
For monitoring and reporting purposes, I need to know how many leaf (aka child) objects are in several of our Active Directory (AD) containers. I tried using the Active Directory Service Interfaces (ADSI) Count property in the script that Listing 1 shows, but this script fails with the error message C:\Scripts\Listing1.vbs(2, 1) Active Directory: Not implemented. How can I determine the number of objects in our AD containers?
As the error message suggests, the reason your script is failing is because the Count property isn't implemented by ADSI's LDAP provider, which means you can't use the property to determine the number of leaf objects in an AD container. You can work around the problem several ways. However, each solution has its drawbacks. The workarounds to count objects in an AD container include
- using a For Each...Next statement combined with a counter variable to enumerate and count the objects in the container
- using ADSI's ADsDSOObject provider (i.e., the OLE DB provider) to perform an ADO search, then using the ADO Command object's RecordSet.RecordCount property to read the number of records that the search returned
- using the new Windows Server 2003 attribute named msDS-Approx-Immed-Subordinates
Listing 2 demonstrates how to use the For Each...Next loop, which is also known as an enumerator, to count leaf objects. The script begins by initializing the counter variable named intContainerCount to 0. The script then binds to the target container and enumerates the objects in that container. During each iteration of the For Each...Next loop, intContainerCount increases by 1. After the loop finishes, the script echoes the total. . . .


karoseeric June 25, 2008 (Article Rating: