script to create external contact in exchange 2013 from csv file

hello,

i need to create 1000 external contact on my exchange 2013 server.

my csv file look like this:

Display Name,Alias,externalsmtpaddress,legacyexchangedn
John SMITH,john.smith,john.smith@domain.com,/o=TEST/ou=Exchange Administrative Group.....

create every contact and use the legacyexchangedn value to create x500 address.
the name entry can be like alias.

thanks for help
cawasakiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Will SzymkowskiSenior Solution ArchitectCommented:
Use the following command below...
$MailContacts = Import-csv "c:\filename.csv"
ForEach ($Item in $MailContacts) {
$Item.DisplayName
$Item.Alias
$Item.ExternalSMTPAddress
New-MailContact -Name $Item.DisplayName -DisplayName $Item.DisplayName -Alias $Item.Alias -ExternalEmailAddress $Item.ExternalSMTPAddress
}

Open in new window


Will.
0
cawasakiAuthor Commented:
hello will

and the x500 address? using legacyexchangedn value

thanks
0
Will SzymkowskiSenior Solution ArchitectCommented:
$MailContacts = Import-csv "c:\filename.csv"
ForEach ($Item in $MailContacts) {
$Item.DisplayName
$Item.Alias
$Item.ExternalSMTPAddress
New-MailContact -Name $Item.DisplayName -DisplayName $Item.DisplayName -Alias $Item.Alias -ExternalEmailAddress $Item.ExternalSMTPAddress
}

$MailContacts = Import-csv "c:\filename.csv"
ForEach ($Contact in $MailContacts) {
$Contact.ExternalSMTPAddress
$Contact.LegacyExchangeDN
Set-MailContact -Identity $Contact.ExternalSMTPAddress -EmailAddresses $Contact.LegacyExchangeDN
}

Open in new window


You have to do this in a 2 step process. First create the new contact and then create the LegacyExchangeDN. I have only used the values you have provided in your CSV. Nothing else needs to change.

Will.
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

cawasakiAuthor Commented:
hello

i need to use legacy exchange dn to create x500 address not legacy dn
0
Will SzymkowskiSenior Solution ArchitectCommented:
i need to use legacy exchange dn to create x500 address not legacy dn

You can only modify the x500 attribute on a contact after it has been created. During the initial process you cannot add this value. That is why it is in 2 steps.

When you are using the Set-MailContact cmdlet, you need to call the mail contact that was created using the Identity parameter. For this i used the ExternalSMTPAddress to call the mail contact and then use the -EmailAddresses parameter to add the LegacyExchangeDN's from your CSV.

Have you tested this out?

Will.
0
cawasakiAuthor Commented:
thanks
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.