Manage Forward Mail by using PowerShell | Office 365 5/5 (2)

7 min read
In the current article, we review the use of the Forward mail PowerShell command in Office 365 and Exchange Online environment.

Forward email rule as the name implies, enable to forward automatically each mail that sent to a particular mailbox to an additional email address.

The “Destination recipient” (E-mail address) could be “internal Mailbox” meaning a recipient from our organization or external recipient, meaning – recipient doesn’t belong to the organization (there is a different PowerShell Parameter for each of the options).

An additional parameter is an option of leaving a copy of the email in the source recipient mailbox or just forward the mail message.

PowerShell | Help & additional information

In case that you are a novice in the PowerShell environment, you can use the following link to get more information about the “first steps” such as: downloading the required PowerShell
software components, how to use the PowerShell console, running a PowerShell script, etc.

Read more
Link Table

PowerShell Naming Conventions & general information

If you want to get more information about the Naming Conventions that we use for this article and get some general tips about: how to work with the PowerShell, read the article: Help and additional information – o365info.com PowerShell articles

Create remote PowerShell session

Before we can use the required PowerShell commands, we need to download and install the Office 365 cmdlets + create remote PowerShell session to Office 365 or Exchange Online. If you need more information about how to create a remote PowerShell session read the following articles: Part 2: Connect to Office 365 by using Remote PowerShell and Part 3: Connect to Exchange Online by using Remote PowerShell

How to use a PowerShell script

Most of the PowerShell articles include a PowerShell script that simplifies the use of the PowerShell commands. If you want to get more information about: How to use a PowerShell script, read the article: Connect to Office 365 and Exchange Online using a script

PowerShell command and Script languish in more details

If you are new to the PowerShell world, you can read more information about PowerShell in Office 365 environment in the article: The Power of PowerShell

In this article, we will demonstrate a couple of scenarios for Mail Forwarding:

  1. Mail forwarding to an internal recipient: John and Suzan are recipients who belong to the office 365 domain names: o365info.com
  2. Mail forwarding to External recipient: John wants to forward each mail that he gets to an external email address: david@hotmail.com
  3. Additional scenarios are: Mail Forwarding in Bulk mode – the option of forwarding email to a destination email address for all the office 365 users and a nice trick of email forwarding that will implement for external contact object.

1. Automatic mail Forwarding to Recipient

1.1 – Forward Email to internal Recipient & save local copy (Default)

PowerShell command Syntax

PowerShell command Example

1.2 – Forward Email to internal Recipient & DONT saves local copy

PowerShell command Syntax

PowerShell command Example

1.3 – Forward Email to External Recipient & save local copy (Default)

PowerShell command Syntax

PowerShell command Example

1.4 – Forward Email to External Recipient & DONT saves local copy

PowerShell command Syntax

PowerShell command Example

1.5 – Create External contact with internal email address + Forward email address (External Email Address)

Step 1: Create External contact with External email address

PowerShell command Syntax

Step 2: Set External contact email address to internal email address and forwarding email address (External email address) PowerShell command syntax:

PowerShell command Syntax

PowerShell command Example
Step 1: Create External contact with External email address

Step 2: Set External contact email address to internal email address and forwarding email address (External email address) PowerShell command syntax:

2. Display information about Forwarding rule

2.1 – Display information about Forwarding rule

PowerShell command Syntax

PowerShell command Example

Adjustments & Customizations:

2.2 – Find all users with Forwarding Address is set to Internal Recipient

PowerShell command Syntax

PowerShell command Example

3. Remove Forwarding rule

3.1 – Turn off Email Automatic Forwarding to internal Recipient

PowerShell command Syntax

PowerShell command Example

3.2 – Turn off email Automatic Forwarding to External Recipient

PowerShell command Syntax

PowerShell command Example

4. Forward Email of ALL Users to Additional email address (Bulk mode)

4.1 – Forward Email of ALL Users to internal Recipient & save local copy

PowerShell command Syntax

Step 1: Save local copy

Step 2: Forward email to the destination recipient (internal\organization recipient)

PowerShell command Syntax

PowerShell command Example
Step 1: Save local copy

Step 2: Forward email to the destination recipient (internal\organization recipient)

4.2 – Forward Email of ALL Users to External Recipient & save local copy

Step 1: Save local copy

Step 2: Forward email to the destination recipient (internal\organization recipient)

PowerShell command Syntax

PowerShell command Example
Step 1: Save local copy

Step 2: Forward email to the destination recipient (External recipient)

4.3 – Forward Email to External Recipient & save local copy | import from CSV File |Scenario 1

Step 1: Enable to option of DeliverToMailboxAndForward

Step 2: Forward email to the destination recipient (internal\organization recipient)

PowerShell command Syntax

Example
Forward Email to External Recipient & save local copy  import from CSV File Scenario 1

4.4 – Forward Email to External Recipient & save local copy | import from CSV File |Scenario 2

Step 1: Enable to option of DeliverToMailboxAndForward

Example
Forward Email to External Recipient & save local copy  import from CSV File Scenario 2

5. Turn off Forwarding rule for ALL Users (Bulk Mode)

5.1 – Turn off email Automatic Forwarding to External Recipient

PowerShell command Syntax

PowerShell command Example

6. Download PowerShell menu script

For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in a PowerShell Script named:
Forward-Messages.ps1
You are welcome to download the script and use it.

download-button-02.png

PowerShell command syntax – Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article


Summary
Article Name
Manage Forward Mail by using PowerShell | Office 365
Description
In the current article, we review the use of the Forward mail PowerShell command in Office 365 and Exchange Online environment.
Author
Publisher Name
o365info.com
Publisher Logo
Print Friendly

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

15 Responses to “Manage Forward Mail by using PowerShell | Office 365”

  1. Great article which makes things easy.
    But what is the difference between -ForwardingAddress and -ForwardingSmtpAddress ???

  2. -ForwardingAddress (internal; within organtization), -ForwardingSmtpAddress (external; forward to an email address outside of your organization)

  3. Forward Email to internal Recipient & save local copy (Default)
    Is not the default setting in my office365 config.
    The default is Forward Email to internal Recipient & DONT save local copy
    So the command will be Set-Mailbox -Identity -ForwardingAddress -DeliverToMailboxAndForward $true

  4. “Forward Email to External Recipient & DONT save local copy” => Does this really work? In our case we failed with tests using ForwardingsmtpAddress and what I could read in other discussions our experience was confirmed.

  5. Thanks to the comments above this is the command that I found to work for “Forwarding Email to External Recipient & save local copy | import from CSV File |Scenario 2”:

    Import-CSV “C:\Temp\Users.csv” | % { $_.Condition = [bool]($_.Condition -as [int]); $_ } | ForEach {Set-Mailbox -Identity $_.mailbox -ForwardingSmtpAddress $_.forwardto -Delivertomailboxandforward $TRUE}

  6. Can someone help me with a script to Forward Email to External Recipient & DONT SAVE local copy | import from CSV File

  7. How come -ForwardingSMTPAddress should be used to forward to external email addresses, but the script in section 4.4 “Forward Email to External Recipient & save local copy | import from CSV File” uses -ForwardingAddress

    Import-CSV “C:\Temp\Users.csv” | % { $_.Condition = [bool]($_.Condition -as [int]); $_ } | ForEach {Set-Mailbox -Identity $_.mailbox -ForwardingAddress $_.forwardto -Delivertomailboxandforward $_.Condition}

    Is this just an error in the script? Or is there a reason for this?

  8. Thank you so much, I used “2.2 – Find all users with Forwarding Address is set to Internal Recipient” to find an old mailbox that was causing problems for us! Very nice resource you have with this page.

  9. Oh my goodness! Amazing article dude! Many thanks, However I am going through issues with your RSS.
    I don’t understand why I cannot join it. Is there anybody else getting identical RSS problems?
    Anyone that knows the solution will you kindly respond? Thanx!!

  10. Danny Nguyen Reply

    Great Article. Is there a way to turn on forwarding for a mailbox and it will stop forwarding after 60 days?

Leave a Reply

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