Creating bulk contacts in Exchange 2007 using Powershell

We needed to create a massive list of mail-enabled in Exchange. We needed a script that flexible enough to allow us to create contacts in multiple OUs, Different primary SMTP addresses, different External email addresses. So we came up with this script, the script operates on the input of a text file which tell it information such as the user’s name, OU to create the contact in and their email addresses. The script will also override the Default Domain Email Address Policy, this means if you have a policy stating that ALL email contacts/users/mailboxes email addresses will have to follow a certain format or pattern, the contacts generated by this script will not be affected by it.

See below for the script:

# This script will create mail-enabled contacts based on the following criterias:
# Create mail-enabled contacts in the OUs specified in the text file
# Create contacts with primarysmtpaddress specified in the text file
# Create contacts with externalemailaddress specified in the text file

# Preparing text file to use with this script
# Create a text file with the following information
# The first line serves as a header row that represents the information that it contains
# Subsequent lines are actual data
# Make sure you remove the # when you create the file
# Firstname,Lastname,PrimarySmtpAddress,OrganizationalUnit,ExternalEmailAddress
# John,Smith,,pnlab.local/pnlab/users/

# Usage: create-contacts contacts.txt

# ———–Start of script ————-
#Reading input parameter from the prompt. Example: create-contacts china.txt

#Reading contact information from the CSV file provided at the prompt
$Contacts = (Import-Csv $CSVUPath)

#Creating mail-enabled contacts using for loop
#For each line read line read from the file create a contact based on the information provided
Foreach ($contact in $contacts)
$Name = $contact.Firstname + ” ” + $contact.Lastname

New-MailContact -Name $Name -FirstName $contact.firstname -LastName $contact.lastname -PrimarySmtpAddress $contact.primarysmtpaddress -OrganizationalUnit $contact.organizationalunit -ExternalEmailAddress $contact.externalemailaddress


See below for the text file:



One comment

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.