Exchange PowerShell: How to Bulk Import/Create Mail Contacts

Exchange2013 PowerShell

I’ve been working a lot with Exchange 2013 recently so will be focusing my next few posts on some PowerShell I have used and found useful to help me setup an Exchange 2013 environment for a new company.

In this post I will look at the process I used to bulk create Contacts.

The first thing you are going to need is a CSV file of contacts that you need to import. In my test CSV file I have three columns, Name, ExternalEmailAddress, and OurganizationalUnit.

Bulk Contacts CSV file

Once you have your source csv file ready, open Exchange PowerShell.

The PowerShell cmdlet we are going to be using it New-MailContact, so lets take a look at it.

Type Get-Help New-MailContact

Get-Help New-MailContact

From the Syntax above we can see all the parameters we can use with the command, so before we bulk import lets try a quick manual import to make sure we get our command right, and contact saved in the correct OU.

New-MailContact -Name “Joe Bloggs” -ExternalEmailAddress “” -OrganizationalUnit “OUFC 1986 Milk Cup”

After running the command we can see Joe Bloggs is in the correct OU. ADUCAnd here he is in the Exchange Control Panel Contacts.

Exchange 2013 - Recipients - Contacts - Mail Contact

So let’s take a look at using Import-CSV along with ForEach-Object to get the job done. In the Exchange PowerShell go to the directory where your CSV file is located, then run the following command. What we are going to do is substitute the actual contacts details with a variable of the column header in line 1 of the CSV file, and we’re going to use -WhatIf to double check everything is in order first of all.

Import-CSV .oufc-contacts.csv | ForEach-Object {New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit $_.OrganizationalUnit -WhatIf}

import-csv foreach-object new-mailcontact -name -externalemailaddress -organizationalunit -whatifSo looking at the output below everything looks to be in order.

import-csv foreach-object new-mailcontact -name -externalemailaddress -organizationalunit -whatif outputSo let’s run the command without -WhatIf.

Import-CSV .oufc-contacts.csv | ForEach-Object {New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit $_.OrganizationalUnit}

import-csv foreach-object new-mailcontact -name -externalemailaddress -organizationalunit outputChecking out the Exchange Control Panel – Contacts and ADUC – OU we can see the addresses have all been imported and created in the correct locations.

Exhcnage 2013 - Recipients - Contacts - After importADUC after import

So the final command we used to import a list of contacts from a CSV file was:

Import-CSV .oufc-contacts.csv | ForEach-Object {New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit $_.OrganizationalUnit}


Technet New-MailContact

Technet Import-CSV

Technet ForEach-Object %

Related Posts:

1. Exchange 2013 Cumulative Update installation tips and best practices

2. Exchange PowerShell: How to enumerate and modify Distribution Group properties

3. Office 365 / Exchange: Stop Display Name Spoofing

4. Exchange 2013 Initial Configuration Settings multi-part series

5. PowerShell: How to add all users in an OU to a Security Group using Get-ADUser and Add-ADGroupMember

3 thoughts on “Exchange PowerShell: How to Bulk Import/Create Mail Contacts

  1. Phil

    I have tried to run the following command:
    Import-CSV .Createnewcontact.csv | ForEach-Object {New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizaonalUnit}

    but l keep getting an error that says: Import -Csv :cannot open file “x:\addingcontacts\.createcontact.csv

    I would appreciate any assistance

  2. Anthony

    How does this script handles contacts that already exist but you may want to change an attribute like external email address, name, etc.?

  3. Yuksel BASTAN

    hi, i have a question and i hope you can help me

    i have a customer list with more than 1000 customers,
    some of them have 1 external mail adres some have more then 2,
    now how can i import this list

    Name FistName LastName ExternalEmailAdress1 ExternalEmailAdress2 ExternalEmailAdress3
    Name1 FistName1 LastName1
    Name2 FistName2 LastName2
    Name3 FistName3 LastName3
    Name4 FistName4 LastName4
    Name5 FistName5 LastName5

Comments are closed.