Enumerating Groups

Enumerating Groups

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Example

This example lists the groups in the "Users" container in the Active Directory. This example opens group information in Active Directory by using Active Directory® Service Interfaces (ADSI). It then uses the IMailRecipient interface aggregated onto the ADSI group object to access information about the e-mail address of the groups.

Visual Basic

Sub List_Groups(DomainName As String)

'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com"

Dim objGroup As IADsGroup
Dim objContainer As IADsContainer
Dim objRecip As CDOEXM.MailRecipient
Dim i As Long
Dim name As String

On Error GoTo Error
' get the users container. Note that user information can also
' be stored in other organizational units (ou).
Set objContainer = GetObject("LDAP://CN=users," + DomainName)

objContainer.Filter = Array("Group")
i = 0

Debug.Print

For Each objGroup In objContainer
   name = objGroup.name
   name = Right(name, Len(name) - 3)
   Set objRecip = objGroup
   If objRecip.TargetAddress = "" And objRecip.X400Email = "" Then
      Debug.Print name + "   (mail disabled)"
   Else
      Debug.Print name + "   (mail enabled)"
   End If
   i = i + 1
Next
Debug.Print "Number of groups found in the DS (in the default container): " + Str(i)
GoTo Ending

Error:
   Debug.Print "Failed while displaying the groups in the default container."
   MsgBox "Run time error: " + Str(Err.Number) + " " + Err.Description
   Err.Clear
Ending:

End Sub


Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.