Recipe 5.8 Determining How Many Child Objects an OU Has

This recipe requires the Windows Server 2003 domain functional level.

5.8.1 Problem

You want to determine if an OU has any child objects or determine how many child objects it contains.

5.8.2 Solution

5.8.2.1 Using a graphical user interface
  1. Open LDP.

  2. From the Menu, select Browse Search.

  3. For Base Dn, enter <OrgUnitDN>.

  4. For Filter, enter (objectclass=*).

  5. For Scope, select Base.

  6. Click the Options button and enter msDS-Approx-Immed-Subordinates For Attributes.

  7. Click OK and Run.

  8. The results will be displayed in the right pane.

5.8.2.2 Using a command-line interface
> dsquery * "<OrgUnitDN>" -scope base -attr msDS-Approx-Immed-Subordinates
5.8.2.3 Using VBScript
' This code displays the approximate number of child objects for an OU set objOU = GetObject("LDAP://<OrgUnitDN>") objOU.GetInfoEx Array("msDS-Approx-Immed-Subordinates"), 0 WScript.Echo "Number of child objects: "  & _              objOU.Get("msDS-Approx-Immed-Subordinates")

5.8.3 Discussion

The msDS-Approx-Immed-Subordinates attribute is new to Windows Server 2003. It contains the approximate number of direct child objects in a container or organizational unit. Note that this is an approximation and can be off by 10% of the actual total for large containers. The main reason for adding this attribute was to give applications an idea of how many objects a container has so that it can display them accordingly.

msDS-Approx-Immed-Subordinates is a constructed attribute, that is, the value is not actually stored in Active Directory like other attributes. Active Directory computes the value when an application asks for it. In the VBScript solution, the GetInfoEx method had to be called because some constructed attributes, such as this one, are not retrieved when GetInfo or Get is called.

You can accomplish similar functionality with Windows 2000 Active Directory, but you need to perform a onelevel search against the OU and count the number of objects returned. This method is by no means as efficient as using msDS-Approx-Immed-Subordinates in Windows Server 2003.

5.8.4 See Also

MSDN: GetInfoEx



Active Directory Cookbook
Active Directory Cookbook, 3rd Edition
ISBN: 0596521103
EAN: 2147483647
Year: 2006
Pages: 456

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net