Manage Forward Mail by using PowerShell

Modificato il Mar, 18 Giu, 2019 alle 5:12 PM

1. Set mail forwording

ADMIN Forwarding (ForwardingAddress)

ADMIN Forwarding (ForwardingAddress) – Forward Email to Recipient & SAVE local copy (Default)

PowerShell command syntax

1

Set-Mailbox <Mailbox> -ForwardingAddress <Destination Recipient E-mail address>


PowerShell command Example

1

Set-Mailbox Angelina -ForwardingAddress Bradp@o365info.com


ADMIN Forwarding (ForwardingAddress) – Forward Email to Recipient DONT SAVE a local copy

PowerShell command syntax

1

Set-Mailbox <Mailbox> -ForwardingAddress <Destination Recipient E-mail address> -DeliverToMailboxAndForward $False


PowerShell command Example

1

Set-Mailbox Angelina -ForwardingAddress Bradp@o365info.com -DeliverToMailboxAndForward $False


USER Forwarding (ForwardingsmtpAddress)

Admin Forwarding (ForwardingsmtpAddress) – Forward Email to Recipient & SAVE local copy (Default)

PowerShell command syntax

1

Set-Mailbox <Mailbox> -ForwardingsmtpAddress <Destination Recipient E-mail address>


PowerShell command Example

1

Set-Mailbox Angelina -ForwardingsmtpAddress Bradp@o365info.com


Admin Forwarding (ForwardingsmtpAddress) – Forward Email to Recipient DONT SAVE a local copy

PowerShell command syntax

1

Set-Mailbox <Mailbox> -ForwardingsmtpAddress <Destination Recipient E-mail address> -DeliverToMailboxAndForward $False


PowerShell command Example

1

Set-Mailbox Angelina -ForwardingsmtpAddress Bradp@o365info.com -DeliverToMailboxAndForward $False


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

1

New-MailContact -Name <Display Name>  -ExternalEmailAddress <External Recipient Email Address>


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

PowerShell command syntax

1

New-MailContact <Display Name> -emailaddresses SMTP:<Office 365 User Email Address>, <External Recipient Email Address>

PowerShell command Example

Step 1: Create External contact with External email address

1

New-MailContact -Name "David bowie"  -ExternalEmailAddress Davidbowie@hotmail.com

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

1

Set-MailContact "David bowie" -emailaddresses SMTP:David@o365info.com,Davidbowie@hotmail.com



2. Display information about mailbox Forwarding settings

Display information about Specific Mailbox Forwarding settings

PowerShell command syntax

1

 Get-Mailbox <MailBox> | FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress


PowerShell command Example

1

 Get-Mailbox Bradp@o365info.com | FL DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress


Find all Recipients (Display list) with ADMIN Forwarding or USER Forwarding

PowerShell command Example

1

Get-Mailbox -ResultSize Unlimited | Where {($_.ForwardingAddress -ne $Null) -or ($_.ForwardingsmtpAddress -ne $Null)} | Select Name, ForwardingAddress, ForwardingsmtpAddress, DeliverToMailboxAndForward 



3. Disable (remove) E-mail Forwarding option

Disable (cancel) ADMIN Forwarding (ForwardingAddress) Specific MAILBOX

PowerShell command syntax

1

Set-Mailbox <MailBox> -ForwardingAddress $Null


PowerShell command Example

1

Set-Mailbox Bradp@o365info.com -ForwardingAddress $Null


Disable (cancel) USER Forwarding (ForwardingsmtpAddress) Specific MAILBOX

PowerShell command syntax

1

 Set-Mailbox <MailBox> -ForwardingSmtpAddress $Null


PowerShell command Example

1

 Set-Mailbox Bradp@o365info.com -ForwardingSmtpAddress $Null


Disable (cancel) ADMIN Forwarding (ForwardingAddress) ALL MAILBOXES (BULK mode)

PowerShell command Example

1

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


Disable (cancel) USER Forwarding (ForwardingsmtpAddress) ALL MAILBOXES (BULK mode)

PowerShell command Example

1

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



4. Export information about forwarding settings

Exoprt informaiton about USER Forwarding rule

Export to CSV file:
PowerShell command Example

1

Get-Mailbox -ResultSize Unlimited  | Where-Object {($_.ForwardingsmtpAddress -ne $Null) }  |  Select-Object DisplayName,Alias, PrimarySmtpAddress, ForwardingAddress, ForwardingsmtpAddress, DeliverToMailboxAndForward, RecipientType,RecipientTypeDetails | Export-CSV C:\TEMP\"All Recipents that have USER Forwarding(ForwardingsmtpAddress).CSV" –NoTypeInformation -Encoding utf8 


Exoprt informaiton about ADMIN Forwarding rule

Export to CSV file:
PowerShell command Example

1
2

 $fwds = Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ForwardingAddress -ne $null } | Select-Object DisplayName,Alias, name, ForwardingAddress

; foreach ($fwd in $fwds) {$fwd | add-member -membertype noteproperty -name “ContactAddress” -value (get-contact $fwd.ForwardingAddress).WindowsEmailAddress} ; $fwds | Export-CSV C:\TEMP\"All Recipents that have Admin Forwarding(ForwardingAddress).CSV" –NoTypeInformation -Encoding utf8 


Exoprt informaiton about User inbox Forwarding rule

Export to CSV file:
PowerShell command Example

1

 $UserInboxRule = ForEach ($i in (Get-Mailbox -ResultSize Unlimited)) {Get-InboxRule -Mailbox $i.DistinguishedName | Where-Object {$_.ForwardTo} | fl MailboxOwnerID,Name,ForwardTo,Description} $UserInboxRule | Out-File C:\TEMP\"User inbox Forwarding rule.txt" -Encoding UTF8



5. 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

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -DeliverToMailboxAndForward $True

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

PowerShell command syntax

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingAddress <Office 365 User Email Address>

PowerShell command Example
Step 1: Save local copy

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -DeliverToMailboxAndForward $True

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

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingAddress Suzan@o365info.com


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

Step 1: Save local copy

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -DeliverToMailboxAndForward $True

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

PowerShell command syntax

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -ForwardingSmtpAddress <External Recipient Email Address>

PowerShell command Example 

Step 1: Save local copy

1

Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"}| Set-Mailbox -DeliverToMailboxAndForward $True

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

1

 Get-Mailbox | Where {$_.RecipientType -eq "UserMailbox"} | Set-Mailbox -ForwardingSmtpAddress  Suzan@Hotmail.com

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

Step 1: Enable to option of DeliverToMailboxAndForward

1
2
3

$Mailboxes= Import-CSV C:\Temp\Users.csv 

ForEach ($Mailbox in $Mailboxes) 

{Set-Mailbox $Mailbox.users -DeliverToMailboxAndForward $True}

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


PowerShell command syntax

1
2
3

$Mailboxes= Import-CSV C:\Temp\Users.csv 

ForEach ($Mailbox in $Mailboxes)

{Set-Mailbox $Mailbox.users -ForwardingAddress Suzan@o365info.com}

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

1

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

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




When you set ForwardingAddress, Exchange will update the altRecipient attribute of the user with the DN of the mail-enabled contact object in the Active Directory.  See below image for your reference.

When you set ForwardingSMTPAddress, Exchange will update the msExchGenericForwardingAddress attribute of the user with the SMTP address of the recipient.  See below image for your reference.


Questo articolo ti è stato utile?

Fantastico!

Grazie per il tuo feedback

Siamo spiacenti di non poterti essere di aiuto

Grazie per il tuo feedback

Facci sapere come possiamo migliorare questo articolo!

Seleziona almeno uno dei motivi
La verifica CAPTCHA è richiesta.

Feedback inviato

Apprezziamo il tuo sforzo e cercheremo di correggere l’articolo