How to set mailbox forwarding in Office 365 using Powershell

When you begin a migration you may require to set mailbox forwarding in Office 365 so that all email that gets sent to the mailbox hosted on Office 365 goes somewhere else. Maybe an on-premise server or some other alternative.

Two ways to set mailbox forwarding in Office 365

There are two ways to do so, one is meant more for an end user and this can be done via Outlook Web App (OWA) using the normal interface and is documented in Forward Email From Office 365.

An administrator can also use this technique too but it isn’t practical if you need to do it for many users. In this case you need to turn to trusty Powershell.

So open up a Powershell window (if you don’t have it set up then read The Basics of Office 365 Powershell) and run the following commands to give you access to the full set of cmdlets:

Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session 
Connect-MsolService
Import-Module Msonline

Once you have got through all that good stuff and entered you admin username and password you can actually do the deed.

There are two useful options here. The first sets the mailbox to foward but doesn’t keep a copy so when you look in the mailbox it will always be empty and then the second which does keep a copy. Make sure you pick the right one.

  1. Set-Mailbox ringo.starr@mycompany.com –ForwardingSmtpAddress ringo@abbeyroad.com –DeliverToMailboxAndForward $false
  2. Set-Mailbox ringo.starr@mycompany.com –ForwardingSmtpAddress ringo@abbeyroad.com –DeliverToMailboxAndForward $true

You can run hundreds or thousands of these commands to turn forwarding on for all your mailboxes if you so wish at the same time.

Eventually you will probably want to turn the Office 365 mailbox forwarding off. At that point you just need to run the following command:

Set-Mailbox ringo.starr@mycompany.com –ForwardingSmtpAddress $null

If you found this post useful then please link to it or comment for us. We like feedback!

 

Subscribe

Subscribe to our e-mail newsletter to receive updates.

No comments yet.

Leave a Reply

* Copy This Password *

* Type Or Paste Password Here *