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.
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
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 “Joe.Bloggs@oufc1986squad.co.uk” -OrganizationalUnit “OUFC 1986 Milk Cup”
After running the command we can see Joe Bloggs is in the correct OU. And here he is in the Exchange Control Panel Contacts.
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}
So looking at the output below everything looks to be in order.
So let’s run the command without -WhatIf.
Import-CSV .oufc-contacts.csv | ForEach-Object {New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit $_.OrganizationalUnit}
Checking out the Exchange Control Panel – Contacts and ADUC – OU we can see the addresses have all been imported and created in the correct locations.
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}
Resources:
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
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
How does this script handles contacts that already exist but you may want to change an attribute like external email address, name, etc.?
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 mail1@mail1.com mail2@mail2.com mail3@mail3.com
Name2 FistName2 LastName2 mail1@mail1.com mail2@mail2.com mail3@mail3.com
Name3 FistName3 LastName3 mail1@mail1.com mail2@mail2.com mail3@mail3.com
Name4 FistName4 LastName4 mail1@mail1.com mail2@mail2.com mail3@mail3.com
Name5 FistName5 LastName5 mail1@mail1.com mail2@mail2.com mail3@mail3.com