Create bulk email contacts in Exchange 2010

I'm trying to run a script that would allow me to create a multiple e-mail contacts from the outside vendors and getting all sorts of errors.
Here is an example of my .csv file

Name, First, Last, External E-mail Address
Adam Scott, Adam,Scott,adams@acc.org

This is a script that i tried to run:

Import-Csv C:\temp\contacts12.csv | ForEach { New-MailContact -Name $_.displayName -Firstname $_.FirstName -LastName $_.LastName -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit "xxxxxxxx.com" }

I've seen some recommendations on this site, followed it and still doesn't work.

Thanks in advance,

sw
swolff1ITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe PriorCommented:
Hii swolff1..

Are you getting any error message ?
0
swolff1ITAuthor Commented:
I'm getting this message:

Cannot bind argument to parameter 'ExternalEmailAddress' because it is null.
    + CategoryInfo          : InvalidData: (:) [New-MailContact], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,New-MailContact
0
Will SzymkowskiSenior Solution ArchitectCommented:
This is the one that i use to create new mail contacts.

Make sure that your column headings in the CSV file are like below...
Name            First             Last            ExternalEmail
Adam           Scott             Adam         Scott AdamScott@external.com

Also in my script below i have defined an $OU variable and $DC variable. These are where the contacts will be stored rather than the default Users container. I also like to point to a single DC in the event the command communicates to another one during the script. If you do not want to use those variables just delete them.

$Users = Import-Csv "c:\filename.csv"
$OU = "External Contacts"
$DC = "dc.domain.com"
            
       ForEach ($EM in $Users) {
            
       $EM.Name
       $EM.First
       $EM.Last
       $EM.ExternalEmail


            New-MailContact -Name $EM.Name -FirstName $EM.First -LastName $EM.Last -ExternalEmailAddress $EM.ExternalEmail -OrganizationalUnit $OU -DomainController $DC

 }

Open in new window


Will.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Murali ReddyExchange ExpertCommented:
There is a space in the csv columns.. "External E-mail Address" It should be ExternalEmailAddress  as per your script reeading. Otherwise it is all good.
0
swolff1ITAuthor Commented:
OK. I'm using this exact script:

 Import-CSV C:\Temp\contacts12.csv | Foreach { New-MailContact -Name $EM.Name -FirstName $EM.First -LastName $EM.Last -ExternalEmailAddress $EM.ExternalEmail -OrganizationalUnit $TEST -DomainController $xxxxx.com }

here is my .cvs file

Name,First,Last,ExternalE-mail
Adam Scott,Adam,Scott,adams@acc
Adil Quyser,Adil,Quyser,adilq@acc

this is an error I'm getting:

Cannot bind argument to parameter 'Name' because it is an empty string.
    + CategoryInfo          : InvalidData: (:) [New-MailContact], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,New-MailContact

what am I missing?

Thanks.
0
Murali ReddyExchange ExpertCommented:
You are mixing both so getting to errors, do one thing.. Do exactly below, copy paste..

$temp = Import-CSV C:\Temp\contacts12.csv
Foreach ($EM in $temp)
{ New-MailContact -Name $EM.Name -FirstName $EM.First -LastName $EM.Last -ExternalEmailAddress $EM.ExternalE-mail -OrganizationalUnit "xxxxxxxx.com"}

Makesure you edit the Organizational Unit with either DN or CanonicalName value of OU.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Will SzymkowskiSenior Solution ArchitectCommented:
Yes, you also have the wrong column name for ExternalEmail.

You have External-Email which will not work.

Will.
0
Joe PriorCommented:
Hi
The $_.ExternalEmailAddress in the command doesn't match the CSV column header you listed. Change the header to ExternalEmailAddress.

Hope it Will work

Thanks
Joe
0
swolff1ITAuthor Commented:
Thank you for your replies,

When I run the script, I don't see any error messages but I don't see any created names in the AD and not in the Exchange "Mail Contacts", below the exact script and .csv  file:

VERBOSE: Connected to RT-MAIL1.xxxxxx.com.
[PS] C:\Windows\system32>$temp = Import-CSV C:\Temp\contacts12.csv
[PS] C:\Windows\system32>Foreach ($EM in $temp)
>> { New-MailContact -Name $EM.Name -FirstName $EM.First -LastName $EM.Last -ExternalEmailAddress $EM.ExternalE-mail -Or
ganizationalUnit $TEST }
>>

.csv file:

Name,First,Last,ExternalE-mail
Adam Scott,Adam,Scott,adams@acc
Adil Quyser,Adil,Quyser,adilq@acc

Thanks again.
0
Will SzymkowskiSenior Solution ArchitectCommented:
You have a - DASH in the external email address column. REMOVE the -DASH.

Will.
0
swolff1ITAuthor Commented:
Here is what I get...


[PS] C:\Windows\system32>Import-CSV C:\temp\contacts12.csv | Foreach ($EM in $temp) { New-MailContact -Name $EM.Name -Fi
rstName $EM.First -LastName $EM.Last -ExternalEmailAddress $EM.ExternalEmail  -OrganizaninalUnit $TEST }
Unexpected token 'in' in expression or statement.
At line:1 char:52
+ Import-CSV C:\temp\contacts12.csv | Foreach ($EM in <<<<  $temp) { New-MailContact -Name $EM.Name -FirstName $EM.Firs
t -LastName $EM.Last -ExternalEmailAddress $EM.ExternalEmail  -OrganizaninalUnit $TEST }
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

my .csv file

Name,First,Last,ExternalEmail
Adam Scott,Adam,Scott,adams@acc
Adil Quyser,Adil,Quyser,adilq@acc


Thanks in advance.
0
Will SzymkowskiSenior Solution ArchitectCommented:
You are not even using my script. Use Exactly what i have typed out in my first post and it will work. I have tested this already and it works in my lab 100%.

As you can see by the error below you are not even putting the import-csv into a variable. USE MY SCRIPT AND IT WILL WORK!
Import-CSV C:\temp\contacts12.csv | Foreach ($EM in <<<<  $temp)

Sorry for the caps, just hate repeating myself.

Will.
0
swolff1ITAuthor Commented:
Gentlemen,

I apologize for the last reply. Murali, your script works, Joe and Will Thank you for pointing out the dash. Feel stupid, I'm not into scripts.

Thank you again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.