Referencing local AD instead of SMTP address

Introduction

This article describes how to reference local AD instead of SMTP address.

1. In Office 365, create contacts for all on-premise users (user@domain.com).

2. In on-premise AD, get the attribute LegacyExchangeDN for all on-premise users.

3. In Office 365, add the LegacyExchangeDN as X500 address to corresponding contacts.

How to implement these steps

1. To get the legacyExchangeDN attribute, go to on-premise Exchange Management Shell, run Get-Mailbox SOMEONE | FL legacyExchangeDN to get this attribute. For example, the LegacyExchangeDN we get is:

X500:/o=ABC/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=someone

2. Connect PowerShell to Exchange Online, steps is listed in the following article:

https://technet.microsoft.com/en-us/exchangelabshelp/cc952755

3. Create contact for USER in Exchange Online:

New-MailContact -Name “Some One” -ExternalEmailAddress user@domain.com

4. Turn off address policy for this contact so Office 365 will NOT overwrite its email address automatically:

Set-MailContact -id “Some One” -EmailAddressPolicyEnabled:$false

5. Add the LegacyExchangeDN as X500 address to this contact:

Set-MailContact -id “Some One” -EmailAddresses “SMTP:user@domain.com;X500:/o=ABC/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=someone”

6. Repeat the above steps for other on-premise mailboxes.

 

Note, if you have a large number of on-premise mailboxes, here is a script to help you to create contacts in batch

A sample script to perform the following steps in batch:

========================

Copy the script to a file e.g., a.ps1

Ensure that the CSV files is created in the similar fashion (as per the sample csv file)

Place a.csv @ C:\ drive

This power-shell scrip will read the items\data from the Excel sheet

o Creates the mail contact with the ExternalEmailAddress (New-mailContact)

o Removes the EmailAddressPolicyEnabled:$false (set-mailcontact)

o Waits for few minutes for the Mail-contact to be created (sleep command)

o Reads the third column from the excel

o Converts them to the Array

o Sets the EmailAddresses on to the Object

========================

Sample Script:

========================

write-host "Start of the Script!"

import-csv c:\a.csv | foreach

{

$obj=new-mailcontact -Name $_.displayName -ExternalEmailAddress $_.primary

$obj | set-mailcontact -EmailAddressPolicyEnabled:$false

write-host "Created the Object "$obj

sleep 5

write-host "Waited for a while for the object to be created!"

$temp=$_.secondary

$arr=$temp.split(";")

foreach ($x in $arr)

{

$obj.emailaddresses += $x

Set-MailContact -Identity $obj.Identity –EmailAddresses $obj.EmailAddresses -customAttribute1 "Migrated user"

}

write-host "done for this contact Object"

}

write-host "End of the Script!"

========================

Sample Excel File (Saved as csv file):

displayName

primary

secondary

Aravind Prabhu

arvindpe@srini.com

smtp:arvindprabhu@phani.com;SMTP:prabhu@ensim.com;X500:/o=ABC/ou=First Administrative Group/cn=Recipients/cn=arvindsmirn

Nagaraj Cobra

cobra@srini.com

smtp:nagarajcobras@phani.com;SMTP:cobraking@adc.com;X500:/o=ABC/ou=First Administrative Group/cn=Recipients/cn=cobrakingsa

Mandar Joshi

mandar@srini.com

smtp:mandarj@phani.com;SMTP:madar@test.com;X500:/o=ABC/ou=First Administrative Group/cn=Recipients/cn=madarj

jaitra

jaitra@srini.com

smtp:jaitra@phani.com;SMTP:jaitra@test.com;X500:/o=ABC/ou=First Administrative Group/cn=Recipients/cn=madarjjaitra

 

Applies To

Office 365 for Enterprise