Office 365 – List all email forwarding rules (PowerShell)

The below is a little example of how to extract a list of the configured Office 365 email forwarding settings using the cmdlet get-mailbox for all mailboxes

Table of Contents

Connecting to exchange

You can either run the command from a local PowerShell session after installing the EXO V2 module. Or I find it easier to use the Cloud Shell from the Exchange Online Admin Centre, up to you.

Method 1 – Cloud Shell

  • Browse to and logon to your Exchange Admin centre https://admin.exchange.microsoft.com/
  • Click the Cloud Shell icon in the top right. If this is your first time using Cloud Shell you will get a quick setup wizard, just follow the steps
  • Enter the command Connect-EXOPSSession to connect to Exchange and wait for the connection to complete

Method 2 – Local PowerShell session

  • If you haven’t already you will need to install the Exchange Online PowerShell V2 module by running the command Install-Module -Name ExchangeOnlineManagement
  • Run the command Connect-ExchangeOnline -UserPrincipalName <UPN> to logon. Replacing <UPN> with your Office 365 admin username.

Listing email forwarding rules

Three columns will be returned;

  • UserPrincipalName: The source mailbox Office 365 username
  • ForwardSmtpAddress: This is the email address messaged are being forwarded to.
  • DeliverToMailboxAndForward: If set to true a copy is kept in the source mailbox in addition to being forwarded, else no local copy is retained at the source.
Get-Mailbox | Where {$null -ne $_.ForwardingSmtpAddress} | FT UserPrincipalName,ForwardingSmtpAddress,DeliverToMailboxAndForward 

Need to find mailboxes with an Out of Office / Auto Responder set?

Take a look at this post Office 365 – List mailboxes with an Out of Office / Auto Reply

11 thoughts on “Office 365 – List all email forwarding rules (PowerShell)”

  1. I’m getting the below error:

    Import-PSSession : Running the Get-Command command in a remote session reported the following error: Processing data for a remote command failed with the following error message: The WinRM client cannot process the request because the server name cannot be resolved.

    Reply
  2. Phil,

    Is it correct that forwarding is configured only if ForwardingSmtpAddress is populated, regardless of whether DeliverToMailboxAndForward is TRUE? Also, does this account for server-side forwarding rules only?

    Reply
    • Hi,

      Yes that is correct all that is required for emails to forward is for ForwardingSmtpAddress to be populated.

      If DeliverToMailboxAndForward is set to true then a copy of the email will remain in the mailbox a copy will be forwarded to the address in ForwardingSmtpAddress.

      If DeliverToMailboxAndForward is set to false the mail is just forwarded and no copy is left in the mailbox.

      My understanding is that it doesn’t matter how the forwarding rule(s) have been created whether that be using Outlook, Outlook web or on the admin side of the fence. The forwarding rule is applied to Excahnge is the same way and exposed using this PowerShell. Does that answer your question?

      Thanks
      Phil

      Reply
  3. I get that Get-Mailbox is not a cmdlet or… I did all recommended (64bit, admin rights at powershell and office etc) but Get-Mailbox is not available.

    Reply
  4. We have a need to temporarily forward all inboxes in O365 Outlook to our on-prem Exchange server. How would we use a version of this script to do that?

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.