Recipe2.13.Enumerating All Existing Exchange Servers


Recipe 2.13. Enumerating All Existing Exchange Servers

Problem

As part of an installation, update, migration, or other administrative task, you might want to find out which Exchange servers already exist in an organization.

Solution

Using a graphical user interface

  1. Launch the Exchange System Manager (Exchange System Manager.msc).

  2. Expand the Administrative Groups node, and then expand each AG that appears below it.

  3. Select the Servers node in each AG. The righthand pane contains the servers in that administrative group, along with their type (basic or clustered), edition (enterprise or standard), version, and modification date.

Using a command-line interface

The following command will query Active Directory to find existing Exchange servers and the version of Exchange installed.

> dsquery * "cn=microsoft exchange,cn=services,cn=configuration,<ForestRootDN>"    -filter "(objectCategory=msExchExchangeServer)" -scope subtree -attr name serialNumber

Using VBScript with WMI
' This code uses WMI to interrogate the Exchange routing table  ' and list all known Exchange servers. ' ------ SCRIPT CONFIGURATION ------  strComputerName = "<ServerName>"    ' e.g., exch01 ' ------ END CONFIGURATION ---------   strE2KWMIQuery = "winmgmts://" & strComputerName &_    "/root/cimv2/applications/exchange"   strE2K3WMIQuery = "winmgmts://" & strComputerName &_     "/root/MicrosoftExchangeV2"    ' display basic attributes using Exchange 2000 WMI provider    set serverList = GetObject(strE2KWMIQuery).InstancesOf("ExchangeServerState")   for each ExchangeServer in serverList     WScript.Echo "Exchange 2000 properties---------"     WScript.Echo "Name:    " & ExchangeServer.Name     WScript.Echo "DN:      " & ExchangeServer.GroupDN     WScript.Echo "Version: " & ExchangeServer.Version   Next   WScript.Echo ""      ' display additional Exchange 2003 provider information   ' real code should include error checking here   Set serverList = GetObject(strE2K3WMIQuery).InstancesOf("Exchange_Server")      For each Exchange_Server in serverList      WScript.Echo "Exchange 2003 properties--------"      WScript.Echo "Name:        " & Exchange_Server.Name      WScript.Echo "FQDN:        " & Exchange_Server.FQDN      WScript.Echo "Admin Group  " & Exchange_Server.AdministrativeGroup   Next

Using VBScript and querying Active Directory
' This code searches Active Directory for Exchange servers  ' ------ SCRIPT CONFIGURATION ------  strBase = "<LDAP://cn=microsoft exchange,cn=services,cn=configuration,<ForestDN>>;"  ' ------ END CONFIGURATION ---------    strFilter = "(objectCategory=msExchExchangeServer);"  strAttrs = "cn;"   ' add more attributes here if desired  strScope = "subtree"    Set objConn = CreateObject("ADODB.Connection")  objConn.Open "Provider=ADsDSOObject;"    Set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)  objRS.MoveFirst  While Not objRS.EOF    wscript.echo objRS.Fields(0).Value    objRS.MoveNext  Wend

Discussion

Using VBScript with WMI

The Exchange WMI providers exposes tons of information about servers in the organization, including the DN (from which you can tell which AG the server's in), its version ("6944" is Exchange Server 2003 RTM, "61xx" is Exchange 2000), and information about which states the disk, CPU, RAM, and network connections are in. Exchange Server 2003 adds a number of other attributes to its provider, which you access with the Exchange_Server class; the code shows how to access the fully-qualified domain name and AG information.

Using VBScript and querying Active Directory

Exchange severs are represented in Active Directory as ordinary computers or domain controllers. Because an Exchange server can be in any domain of the forest, and in any organizational unit (OU) within its domain, the most reliable way to find servers is to look in the configuration naming context (NC), in particular, within the AG containers contained beneath the Microsoft Exchange services container. You can query for any attribute present on the computer object; for this example, we arbitrarily chose CN.

See Also

ExchangeServerState and Exchange_Server classes in MSDN Exchange SDK reference, and Recipe 2.14 for enumerating connectors



Exchange Server Cookbook
Exchange Server Cookbook: For Exchange Server 2003 and Exchange 2000 Server
ISBN: 0596007175
EAN: 2147483647
Year: 2006
Pages: 235

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