Skip to content

Manage Forward Mail with PowerShell | Office 365

Forward mail from a user mailbox in your organization to an internal or external user email address. This is useful if you want to read and respond to messages from another email account or when you want someone else to receive and respond to your email in your absence. In this article, you will learn how to manage forward mail with PowerShell in Exchange Online (Microsoft 365).

Forward mail with PowerShell

The forward email rule automatically enables each email sent to a particular mailbox to an additional email address.

Email forwarding lets you set up a mailbox to forward email messages sent to a user’s mailbox to another user’s mailbox in or outside of your organization.

The destination recipient’s email address could be:

  • Internal mailbox: recipient from your organization
  • External mailbox: recipient outside the organization

There is a different PowerShell parameter for each of the above options. An additional parameter is to keep a copy of the email in the source recipient’s mailbox of the forwarded message.

Forward parameterInternalExternalUser notifiedUser editAdmin edit
-ForwardingAddressxx
-ForwardingSmtpAddressxxxxx

We will show you a few examples to manage Microsoft 365 forward mail with PowerShell:

  • Mail forwarding to an internal recipient: David and Amanda are recipients who belong to the same Microsoft 365 domain name m365info.com.
  • Mail forwarding to an external recipient: David wants to forward each mail he gets to an external email address, Suzan.Wilkins@hotmail.com.
  • Mail forwarding that will implement external contact.
  • Bulk mail forwarding: Forward email of all Microsoft 365 user mailboxes to a destination email address.

Connect to Exchange Online PowerShell

To be able to run the PowerShell commands specified in the current article, you will need to connect to Exchange Online PowerShell.

Connect-ExchangeOnline

Start Windows PowerShell as administrator and run the cmdlet Connect-ExchangeOnline.

1. Set mail forwarding

You can forward all emails sent to a user mailbox to another email address using the two parameters below:

  • ForwardingAddress (internal recipients)
  • ForwardingSmtpAddress (internal & external recipients)

The main difference between these two parameters is that -ForwardingAddress is only used for an internal email address, and -ForwardingSmtpAddress is for an external email address. Also, using -ForwardAddress will not notify the user that their mail is being forwarded. It means the user can’t see or change these forwarding settings, only the admin is able to do so.

Use ForwardingAddress and don’t save local copy email

We want to forward all emails sent to a user mailbox to another user inside the same organization. By default, it will not keep a copy of the forwarded email in the user mailbox.

Note: When you use the parameter -ForwardingAddress, the user will not know that the email sent is forwarded to another mailbox. The user can’t see a forwarding address, meaning that only the admin can change these forwarding settings.

In our example, we want the email sent to David.Kent@m365info.com only delivered to the forwarding mailbox, Amanda.Hansen@m365info.com.

PowerShell command syntax:

Set-Mailbox -Identity "UPN" -ForwardingAddress "Forward Mailbox"

PowerShell command example:

Set-Mailbox -Identity "David.Kent@m365info.com" -ForwardingAddress "Amanda.Hansen@m365info.com"

The mailbox owner (David Kent) will not be able to view and change these mail forwarding settings.

Use ForwardingAddress and save local copy email

By default, the -DeliverToMailboxAndForward parameter is set to $False, meaning the messages are delivered only to the forwarding address. If the parameter is set to $True, messages will be delivered to the mailbox and the forwarding address.

In our example, we want to forward all emails sent to David.Kent@m365info.com to another user in the same organization, Amanda.Hansen@m365info.com. In this case, both mailboxes will receive the email messages in their inbox.

PowerShell command syntax:

Set-Mailbox -Identity "UPN" -ForwardingAddress "Forward Mailbox" -DeliverToMailboxAndForward $True

PowerShell command example:

Set-Mailbox -Identity "David.Kent@m365info.com" -ForwardingAddress "Amanda.Hansen@m365info.com" -DeliverToMailboxAndForward $True

The mailbox owner (David Kent) will not be able to view and change these mail forwarding settings.

Use ForwardingSmtpAddress and don’t save local copy email

You can forward the email sent to the user mailbox to an internal or external email address. By default, it will not keep a copy of the forwarded email in the user mailbox.

Note: Use the parameter -ForwardingSmtpAddress to forward email to an internal or external mailbox. The user mailbox will know about the forwarding settings and can change this.

In our example, we want the emails sent to David.Kent@m365info.com only delivered to the forwarding external mailbox, John.Doe@hotmail.com.

PowerShell command syntax:

Set-Mailbox -Identity "UPN" -ForwardingSmtpAddress "Forward Mailbox"

PowerShell command example:

Set-Mailbox -Identity "David.Kent@m365info.com" -ForwardingSmtpAddress "John.Doe@hotmail.com"

The mailbox owner (David Kent) will know the email is being forwarded to John.Doe@hotmail.com and can change these mail forwarding settings.

Use ForwardingSmtpAddress and save local copy email

By default, the –DeliverToMailboxAndForward is set to $False, meaning the messages are delivered only to the forwarding address. We will set the parameter to $True so that the messages will be delivered to the mailbox and the forwarding address.

In our example, we will show you how to forward an email from David.Kent@m365info.com to an external mailbox so both will receive the email messages.

PowerShell command syntax:

Set-Mailbox -Identity "UPN" -ForwardingSmtpAddress "Forward Mailbox" -DeliverToMailboxAndForward $True

PowerShell command example:

Set-Mailbox -Identity "David.Kent@m365info.com" -ForwardingSmtpAddress "John.Doe@hotmail.com" -DeliverToMailboxAndForward $True

The mailbox owner (David Kent) can see and change these mail forwarding settings.

Create external contact to forward email

If you want to forward the emails to another mailbox without the user knowing, you need to create an external contact.

In our example, we will create a new contact and use the external email address.

PowerShell command syntax:

New-MailContact -Name "Display Name" -ExternalEmailAddress "External Recipient Email Address"

Run the below PowerShell command example:

New-MailContact -Name "Suzan Wilkins" -ExternalEmailAddress "Suzan.Wilkins@hotmail.com"

The PowerShell output shows your newly created contact:

PS C:\> New-MailContact -Name "Suzan Wilkins" -ExternalEmailAddress "Suzan.Wilkins@hotmail.com"

Name                      Alias                                       RecipientType
----                      -----                                       -------------
Suzan Wilkins             SuzanWilkins                                MailContact  

Use ForwardingAddress with external contact

In the previous step, you created a new contact with an external email address. You can forward emails from a user mailbox to this external email address without letting the user mailbox know about these forwarding settings.

In our example, we will forward all emails sent to David.Kent@m365info.com to an external contact, Suzan.Wilkins@hotmail.com.

Run the below PowerShell command example:

Set-Mailbox -Identity "David.Kent@m365info.com" -ForwardingAddress "Suzan.Wilkins@hotmail.com" -DeliverToMailboxAndForward $False

The result is that the user (David) will not know about these changes, as the user can’t see these email forwarding settings, which means that only the admin can change these settings. Also, there is no copy of the forwarded email saved in the user’s mailbox.

2. Display information about specific mailbox forwarding settings

We will show you how to display information about email forwarding settings for a single mailbox and all user mailboxes in your organization.

Display forwarding information about specific mailbox

You can display information forwarding settings, including ForwardAddress and ForwardSmtpAddress of a specific mailbox.

In our example, we will show you the forwarding information settings of David.Kent@m365info.com.

PowerShell command syntax:

Get-Mailbox "UPN" | ft DisplayName, UserPrincipalName, ForwardingSmtpAddress, ForwardingAddress, DeliverToMailboxAndForward

Run the below PowerShell example:

Get-Mailbox "David.Kent@m365info.com" | ft DisplayName, UserPrincipalName, ForwardingSmtpAddress, ForwardingAddress, DeliverToMailboxAndForward

The PowerShell output example:

PS C:\> Get-Mailbox "David.Kent@m365info.com" | ft DisplayName, UserPrincipalName, ForwardingSmtpAddress, ForwardingAddress, DeliverToMailboxAndForward

DisplayName UserPrincipalName       ForwardingSmtpAddress     ForwardingAddress DeliverToMailboxAndForward
----------- -----------------       ---------------------     ----------------- --------------------------
David Kent  David.Kent@m365info.com smtp:John.Doe@hotmail.com Suzan Wilkins                          False

Display list of all mailboxes with FowardingAddress and ForwardingSmtpAddress

Display a list of all the mailboxes that have forwarding addresses to internal or external recipients.

PowerShell command example:

Get-Mailbox -ResultSize Unlimited | Where { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingSmtpAddress -ne $null) } | Select UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward

The PowerShell output example:

PS C:\> Get-Mailbox -ResultSize Unlimited | Where { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingSmtpAddress -ne $null) } | Select UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward

UserPrincipalName          ForwardingAddress                    ForwardingSmtpAddress        DeliverToMailboxAndForward
-----------------          -----------------                    ---------------------        --------------------------
Amanda.Hansen@m365info.com                                      smtp:John.Doe@outlook.com                          True
Brenda.Smith@m365info.com  41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5                                                    True
David.Kent@m365info.com    Suzan Wilkins                        smtp:John.Doe@hotmail.com                         False
Jill.Bates@m365info.com    David Wilkins                                                                           True

3. Disable or remove email forwarding mailbox

We want to show you how to disable the email forwarding option for a single mailbox and all mailboxes. We must use the $null value to remove the email forwarding address.

Disable ForwardingAddress for specific mailbox

You can disable the forwarding address for a specific mailbox. In our example, we will remove the forwarding address for David.Kent@m365info.com.

PowerShell command syntax:

Set-Mailbox "UPN" -ForwardingAddress $null

Run the below PowerShell example:

Set-Mailbox "David.Kent@m365info.com" -ForwardingAddress $null

Disable ForwardingSmtpAddress for specific mailbox

We want to show how you can disable the ForwardingSmtpAddress (external recipient) for a single mailbox. In our example, we will remove the external forwarding address for David.Kent@m365info.com.

PowerShell command syntax:

Set-Mailbox "UPN" -ForwardingSmtpAddress $null

Run the below PowerShell command example:

Set-Mailbox "David.Kent@m365info.com" -ForwardingSmtpAddress $null

Bulk disable ForwardingAddress for all mailboxes

We will show you how to disable all the forwarding addresses for Microsoft 365 mailboxes.

Run the below PowerShell command:

Get-Mailbox -ResultSize Unlimited | Where-Object {($_.ForwardingAddress -ne $null) } | Set-Mailbox -ForwardingAddress $null

Bulk disable ForwardingSmtpAddress for all mailboxes

Bulk disable all the ForwardingSmtpAddresses for Microsoft 365 mailboxes.

Run the below PowerShell command:

Get-Mailbox -ResultSize Unlimited | Where-Object {($_.ForwardingSmtpAddress -ne $null) } | Set-Mailbox -ForwardingSmtpAddress $null

4. Export information about all email forwarding settings

You can export information about all forwarding email addresses of Microsoft 365 mailboxes in your organization. This way, you will have a better overview to search for the different internal or external email addresses.

To export information to a CSV file, you need to create a folder:

  1. Create a folder named temp
  2. Save it in the (C:) drive

Export information about all forwarding addresses to CSV

You can export information about all mailboxes with an internal (ForwardAddress) and external (ForwardSmtpAddress) email address to a CSV file.

Run the below PowerShell command:

Get-Mailbox -ResultSize Unlimited | Where-Object {$_.ForwardingAddress -ne $null -or $_.ForwardingSmtpAddress -ne $null } | Select-Object DisplayName, Alias, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward, RecipientType, RecipientTypeDetails | Export-Csv "C:\temp\All Recipients Forwarding Addresses.csv" -NoTypeInformation -Encoding UTF8

Go to your temp folder in the (C:) drive and open the CSV file with Microsoft Excel to see the results.

Manage Microsoft 365 forward mail with PowerShell export to CSV file

Export information about user inbox forwarding rule to CSV

You can export information about user inbox forwarding rules of all mailboxes to a CSV file.

Run the below PowerShell script:

# Define an array to store the results
$UserInboxRuleResults = @()

# Go through each mailbox
ForEach ($mailbox in (Get-Mailbox -ResultSize Unlimited)) {
    # Retrieve inbox rules for the current mailbox
    $inboxRules = Get-InboxRule -Mailbox $mailbox.DistinguishedName

    # Filter rules with forwarding enabled
    $forwardingRules = $inboxRules | Where-Object { $_.ForwardTo }

    # Process forwarding rules
    ForEach ($rule in $forwardingRules) {
        $ruleInfo = [PSCustomObject]@{
            UserPrincipalName = $mailbox.UserPrincipalName
            RuleName          = $rule.Name
            ForwardTo         = $rule.ForwardTo
            Description       = $rule.Description
        }
        # Add the rule info to the results array
        $UserInboxRuleResults += $ruleInfo
    }
}

# Export the results to a CSV file
$UserInboxRuleResults | Export-Csv -Path "C:\temp\UserInboxRules.csv" -NoTypeInformation -Encoding UTF8

5. Bulk forward email of all users to single email address

We want to show you how to bulk forward emails from all the user mailboxes to a single email address in your organization.

Forward email of all users to internal recipient and save copy email

When you forward an email from a user mailbox to another email address, it will not save a copy of the email in the user inbox by default. If you want all the users in your organization to keep receiving their emails and forward them to another mailbox, then you should follow the steps below.

  1. Save a local copy of the email in the user mailbox

PowerShell command syntax:

Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientType -eq "UserMailbox"} | Set-Mailbox -DeliverToMailboxAndForward $True
  1. Forward the email of all users to the internal destination recipient

Run the below PowerShell example:

Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientType -eq "UserMailbox"} | Set-Mailbox -ForwardingAddress "Office@m365info.com"

Forward email of all users to external recipient and save copy email

We will forward all emails sent to the users in our organization to an external email address and save a copy of the emails. It means we want the messages delivered to the mailbox and the forwarding address. If you don’t want to keep a copy of the email in the user mailbox, you can skip the first step below.

  1. Save a local copy of the email in the user mailbox

PowerShell command syntax:

Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientType -eq "UserMailbox"} | Set-Mailbox -DeliverToMailboxAndForward $True
  1. Forward the email to the destination recipient (external organization recipient)
Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientType -eq "UserMailbox"} | Set-Mailbox -ForwardingSmtpAddress "External Recipient Email Address"

Run the below PowerShell command:

Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientType -eq "UserMailbox"} | Set-Mailbox -ForwardingSmtpAddress "John.Doe@hotmail.com"

Import from CSV file to forward email to external recipient and save local copy

Each time an email arrives at a mailbox, you can forward the email to an external recipient. If you only have a few users in your organization to forward email to external recipient, you can create a CSV file to import it and use it in a script. We will show you two scenarios where you must create a different CSV file.

Scenario 1:

We want to forward emails from multiple user mailboxes in our organization to the same internal recipient.

Create a CSV file with a single column:

  1. Open Notepad or Microsoft Excel
  2. Type Users at the top
  3. List mailboxes
Create CSV file to forward emails to same internal recipient
  1. Create the folder temp if you don’t have it already in the (C:) drive
  2. Name the file Users.csv
  3. Save as type All files (*)
  4. Click Save
Manage Microsoft 365 forward mail with PowerShell save CSV file
  1. Check CSV file with Import-Csv cmdlet

Run Windows PowerShell as administrator. To make sure that PowerShell can read the file, run Import-Csv cmdlet.

Import-Csv "C:\temp\Users.csv"
  1. Enable the option DeliverToMailboxAndForward (optional)
$Mailboxes = Import-Csv "C:\temp\Users.csv" -Encoding UTF8
ForEach ($Mailbox in $Mailboxes)
{ Set-Mailbox $Mailbox.users -DeliverToMailboxAndForward $True }
  1. Forward the email to the internal destination recipient
$Mailboxes = Import-Csv "C:\temp\Users.csv" -Encoding UTF8
ForEach ($Mailbox in $Mailboxes)
{ Set-Mailbox $Mailbox.users -ForwardingAddress "Office@m365info.com" }

Scenario 2:

We want to forward emails from user mailboxes in our organization to a different internal or external recipient, with or without saving a local copy of the forwarded email.

Create a CSV file:

  1. Open Microsoft Excel
  2. Type Mailbox, Condition, ForwardTo as column headers
  3. List mailboxes in the first column (under Mailbox)
  4. Type True or False in the second column (under Condition)
  5. List mailboxes in the third column (under ForwardTo)
Manage Microsoft 365 forward mail with PowerShell create CSV file to import
  1. Save the CSV file in the (C:) drive
  2. Name the file Users.csv
  3. Save as CSV UTF-8
Manage Microsoft 365 forward mail with PowerShell
  1. Run the below PowerShell script
# Import the CSV file
$users = Import-Csv -Path "C:\temp\Users.csv"

# Loop through each row in the CSV data
ForEach ($user in $users) {
    $identity = $user.mailbox
    $forwardTo = $user.forwardto
    $condition = $user.condition -eq "True"

    # Set the mailbox forwarding settings
    Set-Mailbox -Identity $identity -ForwardingSmtpAddress $forwardTo -DeliverToMailboxAndForward $condition
}

Did this help you to manage Microsoft 365 forward mail with PowerShell in your organization?

Read more: Send email with Microsoft Graph PowerShell »

Conclusion

You learned how to manage forward mail with PowerShell Exchange Online. With PowerShell, you can set or remove email forwarding for a single mailbox or all mailboxes. It’s also possible to display information about forwarding settings or export information to a CSV file. At last, you can bulk forward user mailboxes to an internal or external recipient.

Did you enjoy this article? You may also like Enable or disable Exchange ActiveSync mailboxes. Don’t forget to follow us and share this article.

o365info Team

o365info Team

This article was written by our team of experienced IT architects, consultants, and engineers.

This Post Has 12 Comments

  1. This is my problem :

    Set-Mailbox : Cannot bind argument to parameter ‘Identity’ because it is null.
    At line:11 char:27
    + Set-Mailbox -Identity $identity -ForwardingSmtpAddress $forwardTo …
    + ~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Mailbox

    What do I wrong ?

  2. I need help with forward reciept attchments from inbox of all users to and another email address, i used EAC rules but the sender remained the person who sent the invoice, while to setup the automation its needed that the email sender is the user who recieved the invoice and forwards it for approval. please let me know if I am able to explain the scenario and try to help with the same. would be very grateful. I am exploring possible ways to implement via admin center or power automate.

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

  4. Thank you so much, I used “Display list of all mailboxes with FowardingAddress and ForwardingSmtpAddress” to find an old mailbox that was causing problems for us! Very nice resource you have with this page.

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

  6. Wow, great resource. I was just thrown into the mix with O365, and this helps immensely!

Leave a Reply

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