Recipe6.13.Enumerating Connected Mailboxes in a Database


Recipe 6.13. Enumerating Connected Mailboxes in a Database

Problem

You want to find out which mailboxes are in a specific mailbox database.

Solution

Using a graphical user interface

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

  2. In the left pane, expand the appropriate Administrative Groups container, and then expand the Servers container.

  3. Expand the server that contains the target database, then expand the parent SG.

  4. Expand the mailbox database whose contents you want to see.

  5. Select the Mailboxes node in the left pane of ESM. All mailboxes will be listed in the right pane.

  6. If you want to save the list of mailboxes to disk as either an ASCII or comma-separated value file, right-click the Mailboxes folder and select Export List, then specify where you want the file saved.

Using a command-line interface

The following command lists all the mailboxes in a mailbox store:

> dsquery * forestroot -scope subtree -filter "(homeMDB=<mailboxStoreDN>")

For example:

> dsquery * forestroot -scope subtree -filter "(homeMDB=CN=First Storage Group,     CN=InformationStore,CN=BATMAN,CN=Servers, CN=First Administrative Group,      CN=Administrative Groups,CN=Robichaux and Associates, CN=Microsoft     Exchange,CN=Services,CN=Configuration,DC=robichaux,DC=net)"

However, this query runs much faster on Windows Server 2003 Active Directory domains, because Windows Server 2003 can do implict indexing of multilinked values. If you're using Windows 2000 Active Directory, you can get the same data (in a slightly different format) with a more efficient query that retrieves it from the linked attribute list on the mailbox store object. This query form looks a little different:

> dsquery * <mailboxStoreDN> -scope subtree -attr homeMDBBL

This uses the same mailbox DN path as the previous example.

Using VBScript
' This code finds all of the storage groups on a server. For each SG, ' it lists each mailbox database and the mailboxes contained therein.   ' ------ SCRIPT CONFIGURATION ------  strBase = "<LDAP://serverName>;" ' e.g., "batman.robichaux.net"  strComputerName = "<serverName>"     ' e.g., "batman" ' ------ END CONFIGURATION ---------     set theServer = CreateObject("CDOEXM.ExchangeServer")   Set theSG = CreateObject("CDOEXM.StorageGroup")   Set theConn = CreateObject("ADODB.Connection")   theConn.Open "Provider=ADsDSOObject;"     theServer.DataSource.Open strComputerName     ' examine the SGs; for each SG, iterate through its databases and   ' list the mailboxes in it    For Each sg In theServer.StorageGroups       WScript.Echo "Storage group " & Chr(34) & sg & Chr(34)       theSG.DataSource.open sg       i = 0       For Each mailDB In theSG.MailboxStoreDBs         i = i+1         WScript.Echo "  Mailbox database " & i & ": " & mailDB         wscript.Echo "      Users: "          Set objRS = theConn.Execute(strBase & "(homeMDB=" & _                                     mailDB & "); cn; subtree")            objRS.MoveFirst          While Not objRS.EOF                wscript.echo "              " & objRS.Fields(0).Value                objRS.MoveNext          Wend             wscript.echo Chr(13) & Chr(13)           Next     Next WScript.Echo "Done."

Discussion

Finding the mailboxes in a given database is simple, provided you know the DN of the mailbox database itself (which, in turn, is easy to get from the SG object, which is easy to get from the server object) By querying on the homeMDB attribute, you can select the subset of mailboxes in the database of interest. The script for this recipe takes this process up one level by iterating through all of the SGs on the server, then looping through each mailbox database in each SG and displaying the mailboxes that database contains. One caveat, though: a mailbox can exist in Active Directory, but until the user logs onto the mailbox or the mailbox is sent mail, it will not be created in the store.

See Also

Recipe 6.3 for listing the SGs on a server, and Recipes in Chapter 5 for working directly with mailboxes



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