Recipe 17.21. Creating a Query-Based Distribution ListProblemYou want to create a query-based distribution list.
SolutionUsing a graphical user interface
Using a command-line interfaceFirst, you need to create an LDIF file called add_qbdl.ldf with the following contents: dn: CN=<QB DL Name>,<ParentDN> changetype: add cn: <QB DL Name> displayName: <QB DL Name> objectClass: msExchDynamicDistributionList mailNickname: <mail nickname> legacyExchangeDN: <legacy Exchange DN> msExchDynamicDLFilter: <LDAP Filter> msExchDynamicDLBaseDN: <BaseDN> reportToOriginator: TRUE systemFlags: 1610612736 Replace <QB DL Name> with the name of the address list, <mail nickname> with the mail nickname, <legacy Exchange DN> with the appropriate legacy Exchange DN value, <LDAP Filter> with the specific LDAP filter you want to be used to determine group membership, <BaseDN> with the base distinguished name you want used in combination with the filter, and <ParentDN> with the distinguished name of the container you want the group created in. Then run the following command: > ldifde -i -f add-qbdl.ldf Using VBScript' This code creates and mail enables a Query-Based Distribution List. ' ------ SCRIPT CONFIGURATION ------ strParentDN = "<Parent DN>" ' e.g., ou=groups,dc=rallencorp,dc=com strGroupName ="<DL Name>" ' e.g., Sales Dept strBaseDN = "<Base DN>" ' e.g., ou=mail,dc=rallencorp,dc=com strFilter = "<Filter>" ' e.g., (&( department=sales)(homemdb=*)) strLegacyDN = "<Legacy DN of Recipients>" & "/cn=" & strGroupName ' e.g. /o=RALLENCORPMAIL/ou=First Administrative Group/cn=Recipients ' ------ END CONFIGURATION --------- ' Set Dynamic values set objOU = GetObject("LDAP://" & strParentDN) set objGroup = objOU.Create("msExchDynamicDistributionList","cn=" & _ strGroupName) objGroup.Put "msExchDynamicDLBaseDN", strBaseDN objGroup.Put "msExchDynamicDLFilter", strFilter objGroup.Put "displayName", strGroupName objGroup.Put "mailNickname", strGroupName objGroup.Put "legacyExchangeDN",strLegacyDN ' Set static values objGroup.Put "systemFlags",1610612736 objGroup.Put "reportToOriginator",TRUE objGroup.SetInfo Wscript.Echo "Successfully created query-based DL." DiscussionExchange Server 2003 has introduced a new type of distribution list: the query-based DL. These are, as implied by name, distribution lists that are built on the fly based on a query; specifically an LDAP query against Active Directory.
This is an extremely powerful addition for Exchange, but you have to be careful because you can get into trouble with it. Unlike address lists, the query-based DL is resolved each time it is used with an actual LDAP query against Active Directory. This means that the query needs to be efficient. Used enough, a poorly designed query for the DL could severely impact Exchange and Active Directory performance. You will want to use indexed attributes and avoid bitwise operators, the NOT operator, and medial search strings as per normal Active Directory efficient programming guidelines. A medial search string is a search string that has a wildcard somewhere other than at the end of the string (e.g., *llen or j*e). See MSDN for more details (search for "Creating Efficient Active Directory Queries").
Unlike every other object you can mail-enable, when you create a query-based DL you are not using the CDOEXM interface. However, when you create this object with ADUC, the Exchange Management tools must be loaded or the distribution list object will not be properly populated and will not function properly. When creating the object from script or command line, you directly set all of the Active Directory attributes of the msExchDynamicDistributionList object. The specific changes that need to be made are to the following attributes:
Using a graphical user interfaceUsing the GUI is probably the safest way to generate a query for these DLs unless you are very familiar with how to make efficient Active Directory queries. The GUI is configured to help direct you to create queries that are more efficient. If they are created in the ADUC, you will not have to deal with the legacyExchange and mailNickname issues discussed below. Using a command-line interfaceThis example follows the standard LDIF method of importing or modifying an object used in other examples. See the command-line interface discussion from Recipe 17.9.
Using VBScriptThis is the only script in this chapter for mail-enabling objects that doesn't have a nice simple interface. It seems when Microsoft came up with the query-based distribution list object, they totally forgot about people who script and use the command line. You would expect that you could use the CDOEXM MailEnable method, but unfortunately it doesn't work. This is the only script in this chapter that has no choice but to deal with the legacyExchangeDN and mailNickname attributes. See the notes on these two attributes in the command-line interface discussion from Recipe Recipe 17.9. See AlsoMS KB 251631 (XADM: How to Create Distribution Lists in Exchange 2000 Server), MS KB 822897 (How to Troubleshoot Query-Based Distribution Groups), MS KB 829577 (Mixed mod e vs. native mode in Exchange Server 2003), and MSDN: Creating More Efficient Microsoft Active Directory-Enabled Applications |