Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I would like to do is use a Powershell script to create Contacts within a certain folder in Active Directory from a .csv file. This script should allow me to create the first part of an email address based on the information entered in the .csv file.

We are running our exchange server on Windows Server 2003 still and I have Powershell 3.0 on my computer.

This is a script that is close to what I want but not exactly.

$csv = Import-Csv �C:\Contacts.csv� 
foreach($line in $csv) 
New-MailContact -Name $line.DisplayName -ExternalEmailAddress $line.EmailAddress -OrganizationalUnit �Contacts� -Alias $line.Alias 

I am not very experienced with Powershell and if anyone can help me out with this I would be very appreciative.


As requested, Here is an example of one line in my .csv plus headers


TRUCK 327,9426645555

share|improve this question
Exchange 2007?? – TheCleaner Aug 28 '13 at 18:13
Exchange 2003 :( For a few more months at least. – cyborgcommando0 Aug 28 '13 at 18:34
What are you wanting the script to do that it doesn't currently do? At first glance it looks ok...but not sure what you are wanting it to do that it isn't. – TheCleaner Aug 28 '13 at 18:42
The data I have for the Display name should be broken up into First and Last instead of the Display name and the data I have for emails will only include the email address before the domain but will be the same domain email address for each one. – cyborgcommando0 Aug 28 '13 at 19:09
Post in your OP an example line from your csv. – TheCleaner Aug 28 '13 at 19:13
up vote 2 down vote accepted

EDIT: grr...I forgot Exchange 2003...the below only works on Exchange 2007 and above.

For Exchange 2003 you need to use csvde:

An example of how to format the csv file and the csvde command can be found here:



objectClass = Class of the object which you are creating (In your case "contact") DN = Distinguish Name of the object displayName = Display Name of the object proxyAddresses = type:proxy address of the contact object (for example targetAddress = type:target address of the contact object (for example mail = Mail (which you can see in general tab of contact object) mailNickname = alias name of the contact object givenName = First Name sn = Last Name showInAddressBook = for enabling contact in GAL (Even if we did not specify this value the contact will display in the default GAL)

If you want i'll send you a sample CSV file.

You may have to learn Excel tips and tricks to create the CSV file from the input details.

Once you create the CSV file you can use the following command to import the contact objects.

CSVDE -i -f For Ex : CSVDE -i -f c:\test.csv

-i = for specifying import mode

-f = For specifying the input file

Another alternative is a 3rd party utility like AD Bulk Contacts:

OK, here's what I would do (if this were Exchange 2007+ lol)

Setup of csv file

First, open your CSV file in Excel. You need to make your CSV file better for input into PS "script".

  1. Change Name to DisplayName
  2. Copy this DisplayName Column to a new column calledTempName`
  3. Change Email to prefix
  4. Create a new column called FirstName
  5. Create a new column called LastName
  6. Create a new column called Email

Getting FirstName and LastName column populated:

  1. Highlight all of the data in TempName and choose Data then Text to Columns and split out based on a space the first and last names

  2. Now copy the first and last names into their respective new columns you created in #4-5.

Getting Email column populated:

  1. In the email column go to the empty cell adjacent to the the first row of data. ie, there should be the 9426645555 in the prefix column on the same row to the left somewhere, let's say that data is in B3 for example. Here you'll create a formula to concatenate the email prefix with the domain. Something like =CONCATENATE(A2,"") then copy and paste that down the column to get all the email addresses correct.

Now at this point you should have rows that have a DisplayName, FirstName, LastName, and Email that has valid info for a single user. Don't worry about the extraneous columns...we won't use them in the input.

Save the file now as a CSV file and then verify the CSV file looks accurate for input

On to the Powershell script:

$csv = Import-Csv C:\Contacts.csv 
foreach($line in $csv) 
New-MailContact -Name $line.DisplayName -FirstName $line.FirstName -LastName $line.LastName -ExternalEmailAddress $line.Email -OrganizationalUnit Contacts -Alias $line.Alias

That should at least point you in the direction to get you there. If you get stuck, let me know.

share|improve this answer
Thank your for the thorough assistance! Although it appears I have run into a snag. I setup Powershell 2.0 on our Windows Server/Exchange 2003 machine and it seems that the New-MailContact cmdlet is only good for Windows Server 2013 and Exchange Online (Source‌​). Any workaround? – cyborgcommando0 Aug 28 '13 at 21:01
Grr...I keep forgetting the Exchange 2003 part. This works on Exch2007 or greater. For 2003 you'll need to use csvde. I'll update my answer. – TheCleaner Aug 28 '13 at 21:10
Thank you for all your help. I may just wait until we upgrade to a newer version of exchange lol. If I have some more time I will attempt this though and let you know. – cyborgcommando0 Aug 28 '13 at 21:24
Using a 3rd party tool like AD Bulk Contacts will be quick and'll just need to purchase it, but it's fairly cheap. – TheCleaner Aug 28 '13 at 21:38
I think our short term solution is going to be Ad Bulk Contacts and when we upgrade that server later this year I will use powershell for any other contacts. Thanks TheCleaner! – cyborgcommando0 Aug 30 '13 at 14:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.