Enter Search Query:

  • 14049
  • Close

Bulk-create external email contacts in Exchange/Office 365

Say someone asked you to create an exchange distribution group with a thousand new external email addresses. Well, back in the day, you’d download some shady utility off the web and cross your fingers hoping not to spend the rest of your day cleaning up a failed bulk import with ADSIedit. Well, with Exchange 2007 and up/office365, you can use powershell to do this. Here’s how:

[the problem]

Need to batch/bulk create a lot of exchange/active directory contacts with external SMTP addresses.

[requirements]

Powershell with exchange commandlets

[solution]

[step 1] Create a CSV file that contains the information about your external contacts. A lot of information is great if that’s how you want your contacts. Powershell will allow you to import lots of information about each contact from a CSV file. Here’s a sample of a csv file from Microsoft. We’ll call this Sample_A:

exchange-bulk-create-smtp-contacts-external-email

I like my external contacts pretty bare. Just an email address and a name…or even just an email address. Also, note that the New-MailContact command will concatenate the first and last name to create the exchange alias automatically unless you specify that. I don’t like this because in a large organization it’s hard enough to deal with unique aliases for people that have the same names. I don’t need to throw a thousand external contacts with similar names into mix making my exchange alias problem even worse. I typically will modify my CSV file so it just shows two columns: 1. ExternalEmailAddress, 2.Alias. The Alias is just the email address with the @ symbol and the period removed.

Here’s how I typically format my external contact CSV import file. We’ll call this Sample_B:

my-exchange-batch-import-csv-file

[step 2] Create an organizational unit for your new contacts. To the end user there’s no difference, but this will allow you to manage them as one entity. Say you just import them to the default container, well if you’ve already got contacts there, you’ll have to sort through a big pile of crap if someone asks you to delete just those contacts you last imported.

[step 3A] If you like your contacts with lots of information (sample_A.csv), open a powershell command and change directory (CD) to the folder containing your CSV file. Then run the following command:

Import-Csv .sample_A.csv|%{New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit "My Imported Contacts"}

This will create the contacts with some information. Now that they’re created, you’d run the following command to populate each contact with all the other data in your CSV file:

$contacts = Import-CSV .sample_A.csv
$contacts | ForEach {Set-Contact $_.Name -StreetAddress $_.StreetAddress -City $_.City -StateorProvince $_.StateorProvince -PostalCode $_.PostalCode -Phone $_.Phone -MobilePhone $_.MobilePhone -Pager $_.Pager -HomePhone $_.HomePhone -Company $_.Company -Title $_.Title -OtherTelephone $_.OtherTelephone -Department $_.Department -Fax $_.Fax -Initials $_.Initials -Notes $_.Notes -Office $_.Office -Manager $_.Manager}

[step 3B] If you prefer your contacts to look like sample_B where they’ll just have the email address as the name and the alias as the exchange alias, then run the following command:
Import-Csv .sample_B.csv|%{New-MailContact -Name $_.ExternalEmailAddress -Alias $_.Alias -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit "My Imported Contacts"}
That’s really all there is to it.

References:

[download] sample_A.csv

[download] sample_B.csv

[howto] Open a powershell session to Office365

 

May 15, 2014

Related Posts