Directory Services

Enumerating ADAM Users and Groups

[This documentation is preliminary and subject to change.]

To enumerate members of a group, search ADAM using a filter to limit the type of object selected and then apply the Members method to each selected object.

For more information about filtering a query, see Creating a Query Filter.

The following VBScript code example uses the GetObject function to bind to an organizationalUnit object, uses the Filter property to select group objects, outputs the name of each group present, and uses the Members method to output each member of each group.

' Enumerate ADAM groups and group members.

Option Explicit

Dim objADAM	' Binding object.
Dim objGroup   ' Group object.
Dim objMember  ' Member object.
Dim strPath	' Binding path.

' Construct ADAMsPath binding string.
' Change "localhost" to appropriate server.
' Change "389" to port for appropriate instance.
' Change "OU=TestOU,O=Fabrikam,C=US" to appropriate object.
strPath = "LDAP://localhost:389/OU=TestOU,O=Fabrikam,C=US"

WScript.Echo "Bind to: " & strPath
WScript.Echo "Enum:	Groups and members"

On Error Resume Next

' Bind to the object.
Set objADAM = GetObject(strPath)

' Output error if the bind operation fails.
If Err.Number <> vbEmpty Then
	WScript.Echo "Error:   Bind failed."
	WScript.Quit
End If

' Enumerate groups and members.
objADAM.Filter = Array("group")
For Each objGroup in objADAM
	WScript.Echo "Group:   " & objGroup.Name
	For Each objMember in objGroup.Members
		WScript.Echo " Member:  " & objMember.Name
	Next
Next

' Output success or error.
If Err.Number <> vbEmpty Then
	WScript.Echo "Error: Enumeration failed."
Else
	WScript.Echo "Success: Enumeration complete."
End If