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?
 
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
 
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
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

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

All Courses

From novice to tech pro — start learning today.