How to check your Office 365 tenant for auto-forward rules

Use the following steps to check for any Office 365 auto-forward rules to external email addresses.

In this blogpost I’m using Powershell to check for any existing auto-forward rules to external email addresses.

Step 1 Logon to Office 365 using Powershell

$cred=get-credential
$session=new-pssession –configuration Microsoft.Exchange –connectionURI https://ps.outlook.com/powershell –authentication BASIC –allowRedirection:$TRUE –credential $credimport-psSession $session

Step 2 Export the mailbox(es) that have either redirect or forwarding

This produces a list of all mailboxes that exist in the organization where the forwaring or redirect flags are enabled

$mailboxes=get-mailbox –resultSize unlimited
$rules = $mailboxes | foreach { get-inboxRule –mailbox $_.alias }
$rules | where { ( $_.forwardAsAttachmentTo –ne $NULL ) –or ( $_.forwardTo –ne $NULL ) –or ( $_.redirectTo –ne $NULL ) } | ft name,identity,ruleidentity

Step 3 Investigate which rules are in use

Get-InboxRule –identity “username” | fl name,forwardTo,forwardAsAttchmentTo,redirectTo

Step 4 Remove the inbox rule from a specific mailbox

Get-InboxRule -Mailbox username | Remove-InboxRule

Step 5 Remove all the available inbox rules from all mailboxes (if you prefer)

$mbxs = Get-Mailbox

foreach ($mbx in $mbxs) {

    Get-InboxRule  -Mailbox $($mbx.Alias) | Remove-InboxRule

}

2 Comments

  1. How would i export the results from step 2 to a csv??

    1. Author

      Use the following command |Export-Csv -Path .\Filename.csv

Leave a Reply to DavidM Cancel reply

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