Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

The Problem: A good number of people's info was added to my "Mail Contact" list in Exchange Management Console, but not all.

Summary: I'm attempting to add a list of several hundred people from a excel .csv file into my Exchange Management Console (Mail contacts more specifically). A number of the contacts may Already be in the contact list which may have caused my foreach statement to stop running?

My Question: Is there code I can run to check if the members exist then if not, add the member?

I ran this code in powershell in this format:

Import-Csv .\computech.csv | foreach { New-MailContact -Name $_.displayname -FirstName $_.firstname -LastName $_.lastname -ExternalEmailAddress $_.mail -OrganizationalUnit $_.OrganizationalUnit}

Strangely enough it added a good number of the people from the list but not all of them. When I try to run the code now I get this error:

Import-Csv : The member "Aaron" is already present.

"Aaron" is the first member on the list and so the execution immediately stops there

I had previously tried this using this code:

[PS] C:\Windows\system32>Import-Csv \\FILLER\MailboxBackups\contacts.csv | foreach-object{if (Get-MailContact -External
EmailAddress $_.ExternalEmailAddress){write-host $_.ExternalEmailAddress 'is a duplicate entry!!!!'} else {New-MailConta
ct -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}}

But I received the same "Aaron" is already present error lol. Any help would be greatly appreciated

--------UPDATE------------ I found out that not all of the contacts were added because of Alias conflicts. Aliases were common names like "bob" which are sure to already exist. Do people normally use numbers to get around this, or use a users email address instead of simple names?

share|improve this question
up vote 1 down vote accepted

The article Importing exchange Mail Contacts using powershell suggests this code :

Import-Csv .\ExternalContacts.csv|
    foreach-object{if (Get-MailContact -anr $ {write-host $ 'is a duplicate entry!!!'}     
    else {New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}
share|improve this answer
if you read my question above, my last statement stated that I had previously tried this code and it didn't work. If you have insight as to why my version of it didn't work (as shown in my question) that could be helpful. – Mike Kellogg Feb 19 '13 at 15:13
The above uses the anr parameter for ambiguous name resolution search over: CommonName (CN), DisplayName, FirstName, LastName, Alias. – harrymc Feb 19 '13 at 15:47
@Mike: Please comment. – harrymc Feb 25 '13 at 10:06
didn't check the validity of this code because I haven't needed to use the function since. Will definitely try in the future. – Mike Kellogg Mar 7 '13 at 16:51
try '-ErrorAction SilentlyContinue' to skip duplicated entries. – Root Loop Feb 4 '15 at 14:56

To answer your update, some orgs will do first inital last name (mmoore in my case), and if that is taken then append a number to that or use first initial middle initial last name, but a transform of that is common practice.

So, when importing, you could add a condition to check for the alias that's about to be inserted, and if it exists then transform it until a unique one is generated. I could add code if you like but I think you know where I'm getting at.


I should add this is usually done with AD user names typically, so you could also try assigning their AD user name as their alias, if you implement AD.

share|improve this answer

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.