How To Enumerate Connected Sites & Servers in Exchange with ADSI (200726)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0
  • Microsoft Visual Basic Learning Edition for Windows 5.0, when used with:
    • the operating system: Microsoft Windows NT
    • the operating system: Microsoft Windows 95
  • Microsoft Visual Basic Professional Edition for Windows 5.0, when used with:
    • the operating system: Microsoft Windows NT
    • the operating system: Microsoft Windows 95
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0, when used with:
    • the operating system: Microsoft Windows NT
    • the operating system: Microsoft Windows 95
  • Microsoft Exchange Development Kit (EDK) 5.5, when used with:
    • the operating system: Microsoft Windows NT
    • the operating system: Microsoft Windows 95
  • Microsoft Exchange Server 5.5
  • Microsoft Active Directory Service Interfaces 2.0

This article was previously published under Q200726

SUMMARY

The following sample code in Visual Basic illustrates using ADSI LDAP provider objects to enumerate all the connected sites and servers in an Exchange organization. In order to use this code, you must have at least one Exchange 5.5 server in your connected sites. You should also have the latest ADSI client runtime (version 2.0 or better) installed on your system.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open a new Standard EXE Visual Basic Project.
  2. Add a Module.
  3. Make a reference to the Active DS Type Library.
  4. Set the Startup Object to Sub Main.
  5. Copy and paste the following sample code into the Module:
' Sample to enumerate sites and servers in an Exchange Organization
' using ADSi objects

   Option Explicit

   Sub Main()

   Dim objOrg As IADsContainer
   Dim objOU As IADsContainer
   Dim objConfig As IADsContainer
   Dim objServers As IADsContainer
   Dim obj As IADs

   ' Replace "Server" with the name of any Exchange 5.5 server in one of
   ' the connected sites you want to enumerate.
   Set objOrg = GetObject("LDAP://Server")
   Debug.Print objOrg.Name

   ' filter passes organizationalUnit and any classes derived from it
   ' such as View-Root
   objOrg.Filter = Array("organizationalUnit")
   For Each objOU In objOrg

    With objOU
    ' Test that the most derived class is organizationalUnit
    If objOU.Class = "organizationalUnit" Then
        Debug.Print "Site: " + .Name
        objOU.Filter = Array("Container")
        For Each objConfig In objOU
            With objConfig
            ' Test for cn=Configuration (root container)
            If .Name = "cn=Configuration" Then
                ' In case configuration might have non-containers
                .Filter = Array("Container")
                For Each objServers In objConfig
                    With objServers
                    ' Test for cn=Servers inside of Configuration container
                    If .Name = "cn=Servers" Then
                        .Filter = Array("Computer")
                        For Each obj In objServers
                            With obj
                            Debug.Print Chr(9) & "Server: " & .Name
                            Debug.Print Chr(9) & "ADsPath: "; .ADsPath
                            End With
                        Next obj
                    End If
                    End With
                Next objServers
            End If
            End With
        Next objConfig
    End If
    End With

   Next objOU
   Debug.Print "End Enumeration"

   End Sub
				

REFERENCES

Information on ADSI version 2.0 is included in the Platform SDK section of MSDN after October 1997. ADSI is also available on the following Web site:

http://www.microsoft.com/windows/server/overview/features/ataglance.asp

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbDSWManage2003Swept kbAPI kbhowto kbMsg KB200726