Adding Hybrid Exchange in retrospect (post-migration)

Back to Blog

Adding Hybrid Exchange in retrospect (post-migration)

Sometimes organizations that have already migrated email to Office 365 using a third party tool or a cutover method would like to “go hybrid” and install Azure AD Connect after the fact. Usually the driving factors here are password sync and Single Sign-On with the local domain.

To their disappointment, this is where they learn that they have to keep an Exchange server on-premises. But what if they have already removed the last Exchange Server from their environment? Or perhaps their AD has never had Exchange in it–if the mail was hosted elsewhere prior to 365.

In that case they would need to install a new Exchange Server (or at least extend the schema to get the right attributes). Once that is done, they are also required to export the mail attributes from the cloud (specifically the primary SMTP address and all aliases / proxyAddresses), and then import them back into the local Active Directory.

You can accomplish this part as follows in PowerShell. From the EXO PowerShell module (using Connect-EXOPSSession):

$CSVFile = “C:\Temp\aliases.csv”

Get-Recipient -ResultSize unlimited | Where {$_.RecipientType -eq “UserMailbox”} | Select-Object DisplayName, Alias, PrimarySmtpAddress, @{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses) -join “,”}} |
Export-CSV $CSVFile

That will give you a csv file that you can work with to import the values to AD, for example (using Import-Module ActiveDirectory):

Import-CSV $CSVFile | ForEach-Object{

$User = $_.PrimarySmtpAddress
$proxyAddresses = $_.EmailAddresses

## Give a status to the user

Write-Host “Working on $User…” -ForegroundColor White

## Add the PrimarySmtpAddress from the csv file

Write-Host “Adding primary Email address for $User from the CSV file…” -ForegroundColor Yellow
Get-ADUser -Filter {UserPrincipalName -EQ $User} | Set-ADUser -EmailAddress $User

## Add the alias addresses from the csv file

Write-Host “Adding proxyAddresses entires for $User from the CSV file…” -ForegroundColor Yellow
Get-ADUser -Filter {UserPrincipalName -EQ $User} | Set-ADUser -Add @{proxyAddresses = ($proxyAddresses -split “,”)}

Write-Host “Done!” -ForegroundColor Green

Leave a Reply

Back to Blog

Helping IT Consultants Succeed in the Microsoft Cloud

Have a Question? Contact me today.