We help IT Professionals succeed at work.

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
Comment
Watch Question

Will SzymkowskiSenior Solution Architect
Most Valuable Expert 2015
Top Expert 2015

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

Author

Commented:
hello will

and the x500 address? using legacyexchangedn value

thanks
Senior Solution Architect
Most Valuable Expert 2015
Top Expert 2015
Commented:
$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.

Author

Commented:
hello

i need to use legacy exchange dn to create x500 address not legacy dn
Will SzymkowskiSenior Solution Architect
Most Valuable Expert 2015
Top Expert 2015

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

Author

Commented:
thanks