Saturday, April 14, 2018

Exchange Bulk Create Dynamic Distribution Lists From CSV

Last year I migrated our company from Notes to Exchange 2016, and just recently found out that we're "missing" several Dynamic Distribution Lists...by several I mean 53.
So, instead of doing that all by hand, I thought building a CSV with that info sure would be handy!
I'll show you how to create multiple DDLs from a CSV, using PowerShell.

We're going to create a CSV with all the necessary information to automatically create these DDLs, and we'll be using the AD Custom Attribute 15 for the Location Codes for each group.
Since most DDLs are built by location or OU, that will be the scope of this post. Feel free to leave a comment if you need some other filterable properties.

**Note** We use Attribute15 in my environment to specify the location code (because we run a Resource Forest which syncs over from the Accounts forest), but you can change that to whatever attribute you use...for instance you can choose "ConditionalStateOrProvince" to use the State attribute.
Just change the "Attribute15" column heading to "State" in your CSV.

Create the CSV

Now, we'll create a CSV file in the following format:

Dynamic Distro CSV

In the example CSV, we'll use the following locations (which are populated for my users within CustomAttribute15 in AD):

NYC (New York)
CHI (Chicago)
DAL (Dallas)
BOS (Boston)

The CSV will specify the following:

Name - DDL Display Name

Alias - DDL Alias

OU - The Organizational Unit where the DDLs will be created e.g. "domain.com/DistributionLists"

Attribute15 - CustomAttribute15 (where the location code is stored)

Recip (RecipientTypes) - "MailboxUsers, MailContacts, MailUsers"

Email (PrimarySMTP) - The primary email address of each DDL e.g "LocAllUsers@domain.com"

Container (RecipientContainer) - Where the DDL will query AD to pull the members from e.g. "OU=Users,DC=domain,DC=com"

Now, save the CSV somewhere like: c:\temp\newdlls.csv

Create the Dynamic Distribution Groups

Once you have your CSV built and saved, run the following cmdlet in the EMS (Exchange Management Shell):

Import-CSV "C:\temp\newddl.csv" | % {New-DynamicDistributionGroup -Name $_.Name -OrganizationalUnit $_.OU -ConditionalCustomAttribute15 $_.Attribute15 -IncludedRecipients $_.Recip -PrimarySmtpAddress $_.Email -RecipientContainer $_.Container}

The cmdlet will call each heading in the CSV, and pipe in the values you have specified for each group.

**Note** If you're using something other than Attribute15 like "State" for instance, in the above cmdlet, change the "-ConditionalCustomAttribute15" switch to "-ConditionalStateOrProvince $_.State" which will then match your CSV heading.

**Note** Depending on how many DDLs you're creating and how large your environment is, this could take a while - meaning the Shell might sit there and "do nothing" for a bit.

Once the cmdlet is finished, you'll see the new DDLs in your "domain.com/DistributionLists" OU, and they'll be populated from the Recipient Container we specified  (OU=Users,DC=domain,DC=com).

All done!

To get a membership report and see that our filters work, you can grab a script I wrote in this post, which will output a nice and pretty HTM file for ya!

No comments:

Post a Comment