Recipe 2.13. Enumerating All Existing Exchange ServersProblemAs part of an installation, update, migration, or other administrative task, you might want to find out which Exchange servers already exist in an organization. SolutionUsing a graphical user interface
Using a command-line interfaceThe 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 DiscussionUsing VBScript with WMIThe 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 DirectoryExchange 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 AlsoExchangeServerState and Exchange_Server classes in MSDN Exchange SDK reference, and Recipe 2.14 for enumerating connectors |