
Where Can You Use LDAP Queries?
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.
Doing a Search Using Active Directory Users and Computers
The following example illustrates how to search using Active Directory Users and Computers:
-
Open Active Directory Users and Computers.
-
Right-click the domain object and select Find.
-
Click the drop-down list next to Find, and then select Custom Search.
-
From the next screen, select the Advanced tab.
-
Type the appropriate LDAP statement under Enter LDAP query.
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.
Doing a Search Using LDP
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.
Doing a Search Using LDIFDE
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.
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.