Forward Mail From Exchange (On-Prem) To Office 365

KB ID 0001467

Problem

WARNING: Do not do this, if you are carrying out a Hybrid migration to Office 365!

I’ve been doing an On-Prem to Office 365 migration recently. It was a little unusual because the ‘on-prem’ Exchange was not in the clients domain. So rather than migrate all the mail to their domain, and them migrate it to Office 365  we chose to use a third party migration solution ODME (Quest On Demand Migration for Exchange). 

So using their tool I could migrate the ‘DATA’ and then the plan is to use the Quest CPUU (Client Profile Update Utility) to repoint all the clients Outlook profiles to Office 365.

Thats fine but how to keep the mail ‘up to date’ in both locations while they are being migrated. I thought (incorrectly) that the Quest ODME would do this, but forwarding from on-prem Exchange deployments is not supported.

This is what I wanted to do;

Exchange Forward Mail to Office 365

Then I could migrate everyone, then move the mail flow to Office 365, by simply changing the DNS (MX) Records.

Solution

I’ve covered forwarding of mail before in this previous article (you might want to have a read though that one fist).

Microsoft Exchange – Forwarding Mail To External Email Addresses

So I know what the commands are, and I can supply the usernames and the email addresses to forward to, in a CSV file.

Firstly: You need to enable Forwarding to your office 365 email address*

New-RemoteDomain -Name YOUR-DOMAIN-O365 -DomainName your-domain.onmicrosoft.com
Get-RemoteDomain YOUR-DOMAIN-O365 | Select DomainName, AutoForwardEnabled

*Note: I’m using the ‘onmicrosoft.com‘ tennant email as it is already publicly routable, and lets me still have my live mail feed pointed to the on-prem Exchange.

Now assuming you have all your on-prem usernames and their Office 365 email address sin a CSV file like so,

CSV file

And you have saved the CSV file as C:\Temp\Office-365-Users.csv, use the following script.

Import-Csv -Path "C:\Temp\Office-365-Users.csv" | ForEach-Object {
	Set-Mailbox -Identity $_.'Source-User' -DeliverToMailboxAndForward $true -ForwardingSMTPAddress $_.'Target-Mailbox'
}

To test it worked;

Get-Mailbox | Where {$_.ForwardingSMTPAddress -ne $null} | Select Name, UserPrincipalName, ForwardingAddress, ForwardingSMTPAddress, DeliverToMailboxAndForward

To Remove it when you have finished;

Get-Mailbox | Set-Mailbox -DeliverToMailboxandforward $False -ForwardingSMTPAddress $Null -ForwardingAddress $Null

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

1 Comment

  1. This is great! But you should do this at 12:01 am and then make sure your ODME settings in the migration plan are to 11:59pm the previous day. That way you won’t double up and migrate email that has been forwarded.

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *