Topic Last Modified: 2011-01-13
By William Taylor
This article discusses Lightweight Directory Access Protocol (LDAP) queries, which can be useful, but confusing, when troubleshooting Microsoft® Exchange Server and its relationship to its directory. This article provides basic information about LDAP queries.
(givenName=John)
(&(givenName=John)(l=Dallas))
(!givenName=John)
!
(title=*)
(givenName=Jo*)
(&(givenName=John)(|(l=Dallas)(l=Austin)))
(&(msExchUserAccountControl=2)(!msExchMasterAccountSID=*))
While working with Exchange Server, you encounter situations that use LDAP strings. For example, whenever you set up a recipient or mailbox manager policy or an address list filter, or when you search the Active Directory® directory service, Exchange Server utilizes LDAP. In the next sections, some of the ways in which you can use LDAP statements are discussed.
The following example illustrates how to search using Active Directory Users and Computers:
This example attempts to find all objects that either have prez for their title or test for the start of their name. If you click Find Now, you should see the appropriate output, as shown in the following screenshot.
You can also search using LDP, which is included in Microsoft Windows Server™ 2003 and Windows® 2000 Server support tools. This tool gives you the ability to not only search the domain container, but also the Configuration container. You first would open LDP and connect to a valid domain controller. Then you need to bind using appropriate credentials. Select View, and then select Tree. Leave the Base DN field blank, and click OK. Navigate to the container that you want to search, right-click the container, and select Search.
A dialog box appears that should have the correct value in the Base DN field. Type the LDAP statement that you want to filter by, and something similar to the following should appear.
If you want to search all of the containers below the level you are currently at, make sure to select the option button for Subtree. Click Run, and it should find all of the matches.
There may be times when you need to do a search for a set of objects that meet a certain criteria, and you want to build a list of those users. LDIFDE is a command-line tool that you can use to build this list. Suppose you want to find and save a list of all the users whose mailNickName starts with Jeff. You could then run the following command.
C:\>ldifde -d "DC=witaylorroot,DC=com" -f c:\output.txt -r "(&(objectClass=user)(mailNickName=jeff*))
In this example, you would find three objects and export all of their attributes into the output .txt file that you specified. If you are exporting the results for thousands of users, however, the export file will be too large. There is a different option. You can use the -l (lowercase L) switch to specify which attributes to export. The distinguished name will always export, but if you want nothing else, you can add -l nothing to the string, and that would streamline the output. An example of this is the following command.
-l
nothing
C:\>ldifde -d "DC=witaylorroot,DC=com" -f c:\output.txt -l nothing -r "(&(objectClass=user)(mailNickName=jeff*))
Consider that in this case, you want to use the LDIFDE export referenced earlier, but only want to include the homeMDB attribute in the output. You must use the following command.
C:\>ldifde -d "DC=witaylorroot,DC=com" -f c:\output.txt -l "homeMDB" -r "(&(objectClass=user)(mailNickName=jeff*)) dn: CN=jeff,OU=55Users,DC=witaylorroot,DC=com changetype: add homeMDB: CN=Private Information Store (WITAYLORNT4EX55),CN=First Storage Group,CN=InformationStore,CN=WITAYLORNT4EX55,CN=Servers,CN=WITAYLORMIXEDSITE,CN=Administrative Groups,CN=WITAYLORORG,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=witaylorroot,DC=com dn: CN=jeff2,CN=Users,DC=witaylorroot,DC=com changetype: add homeMDB: CN=Private Information Store (WITAYLORNT4EX55),CN=First Storage Group,CN=InformationStore,CN=WITAYLORNT4EX55,CN=Servers,CN=WITAYLORMIXEDSITE,CN=Administrative Groups,CN=WITAYLORORG,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=witaylorroot,DC=com dn: CN=jeff3,CN=Users,DC=witaylorroot,DC=com changetype: add homeMDB: CN=Private Information Store (WITAYLORNT4EX55),CN=First Storage Group,CN=InformationStore,CN=WITAYLORNT4EX55,CN=Servers,CN=WITAYLORMIXEDSITE,CN=Administrative Groups,CN=WITAYLORORG,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=witaylorroot,DC=com
If you are doing an export without restricting what attributes are exported, you might want to use the -n switch to suppress any values that would normally be included. This will help prevent the export file size from getting too large.
-n
To obtain the ADModify tool, contact Microsoft Product Support Services. For more information about how to contact Microsoft Product Support Services, see the Microsoft Help and Support Web site.
To obtain the ADModify tool from a third-party Web site, see the following GotDotNet Web site: ADModify.NET: Workspace Home.
ADModify is a tool that Microsoft Product Support Services uses on a daily basis. With large Active Directory environments, it is not always easy to add an entire organizational unit (OU) that could have thousands of users in it to the list on the right side, and then parse through all of them to find the users you need to change. There is an alternative. On the first screen, choose Modify Existing User Attributes and click Next. On the Modify Active Directory Users screen, there is an Advanced button.
If you click the Advanced button, the Custom LDAP Filter dialog box appears. In this dialog box, you type the LDAP filter that you want to use. In this example, you only want to list the groups that are mail-enabled. It would look like the following.
Next, click OK. Select the OU or the domain where you want ADModify to search. If you want it to look in lower-level containers within the one you selected, make sure to select Traverse Subcontainers when Enumerating Users. Click Add to List, and then click Yes when warned about how long it could take. The objects that meet the criteria you specified should now appear in the right pane.
From here, highlight the objects that you want to modify, and continue with the wizard.
For more information, see the following Microsoft Knowledge Base articles:
(&;;(givenName=John)(|(l=Dallas)(l=Austin)))