When someone gets into a Microsoft 365 mailbox, resetting the password is rarely the end of it. A common move after a successful phish is to create an inbox rule that forwards invoices to an outside address, or quietly moves replies from the finance contact into RSS Feeds or Archive so the real user never sees them. The rule keeps working long after the password has changed, and in a 10 or 20 person tenant nobody is looking at inbox rules unless something has already gone wrong.

This guide walks through a full audit you can run in under an hour on a small tenant: every inbox rule, every mailbox-level forward, the audit log entries that show when rules were created, and the one tenant setting that blocks external auto-forwarding entirely.

What you need before you start

You need an account with the Exchange Administrator role (or Global Administrator), a Windows machine with PowerShell 7 or Windows PowerShell 5.1, and the Exchange Online PowerShell module. If you have not installed the module yet:

Install-Module ExchangeOnlineManagement -Scope CurrentUser
Connect-ExchangeOnline -UserPrincipalName admin@yourtenant.com

Run the audit from an admin workstation, not from a user’s PC, and keep the output files somewhere only admins can read. The export will contain addresses and folder names that tell an attacker a lot about how the business runs.

Step 1: Export every inbox rule in the tenant

Get-InboxRule works one mailbox at a time, so loop through every user and shared mailbox. The -IncludeHidden switch returns hidden rules as well, which is worth including because some rules are not visible in Outlook.

$mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox, SharedMailbox

$rules = foreach ($mbx in $mailboxes) {
    Get-InboxRule -Mailbox $mbx.UserPrincipalName -IncludeHidden |
        Select-Object @{n='Mailbox';e={$mbx.UserPrincipalName}},
            Name, Enabled, Priority, From, SubjectContainsWords,
            ForwardTo, ForwardAsAttachmentTo, RedirectTo,
            MoveToFolder, DeleteMessage, MarkAsRead, Description
}

$rules | Export-Csv .\inbox-rules.csv -NoTypeInformation

Hidden results include some system rules that Exchange creates on its own, such as junk email handling. Do not delete anything just because it is hidden. Read the Description column first; it spells out the rule’s conditions and actions in plain English.

Step 2: Filter for the rules that matter

Most inbox rules are harmless: newsletters into a folder, a manager’s mail flagged. The ones to look at first are rules that send mail outside the tenant, delete it, or hide it.

$rules | Where-Object {
    $_.ForwardTo -or $_.ForwardAsAttachmentTo -or $_.RedirectTo -or
    $_.DeleteMessage -or
    ($_.MarkAsRead -and $_.MoveToFolder)
} | Format-Table Mailbox, Name, Enabled, Description -Wrap

Things that should get a second look:

  • Any forward or redirect to an address outside your own domains, especially a free mail service.
  • Rules that match words like invoice, payment, wire, bank, ACH or the name of a regular vendor.
  • Rules that mark mail as read and move it to RSS Feeds, RSS Subscriptions, Conversation History or Archive. Those folders are rarely opened, which is exactly why they get used.
  • Rule names that are a single character, a dot, or a string of punctuation.
  • Rules on a mailbox whose owner has no reason to filter mail at all.

If you find one, do not just delete it. Disable it, take a screenshot or keep the CSV row, and treat the mailbox as compromised until you know otherwise. The rule is evidence, and your ransomware or incident plan should say who is told and what gets preserved. If you do not have one yet, our guide on building a ransomware response plan covers the roles and the first hour.

Disable-InboxRule -Mailbox user@yourtenant.com -Identity "RuleName"

Step 3: Check mailbox-level forwarding

Inbox rules are not the only way to forward mail. An admin, or an attacker with admin rights, can set forwarding on the mailbox itself, and users can set it from Outlook on the web. Those settings live on the mailbox object, not in the rules:

Get-Mailbox -ResultSize Unlimited |
    Where-Object { $_.ForwardingSmtpAddress -or $_.ForwardingAddress } |
    Select-Object UserPrincipalName, ForwardingSmtpAddress, ForwardingAddress, DeliverToMailboxAndForward |
    Format-Table -AutoSize

ForwardingSmtpAddress is usually the one a user or attacker set, and it can point anywhere. ForwardingAddress points to a recipient object inside the tenant. DeliverToMailboxAndForward tells you whether the user still gets a copy; when it is false, mail goes out and the user sees nothing.

To remove a forward you have confirmed is unwanted:

Set-Mailbox user@yourtenant.com -ForwardingSmtpAddress $null -DeliverToMailboxAndForward $false

Step 4: Find out when rules were created

The current rule list tells you what exists. The unified audit log tells you who created or changed it and from where. If auditing is enabled in the tenant, search the last 90 days for rule activity:

Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-90) -EndDate (Get-Date) `
    -Operations New-InboxRule, Set-InboxRule, UpdateInboxRules -ResultSize 1000 |
    Select-Object CreationDate, UserIds, Operations, AuditData |
    Export-Csv .\inbox-rule-audit.csv -NoTypeInformation

New-InboxRule and Set-InboxRule usually come from Outlook on the web or PowerShell, while UpdateInboxRules is typical of the Outlook desktop client. The AuditData column is JSON and includes the client IP address. A rule created from an IP address in another country, a few minutes after an unusual sign-in, is about as clear a signal as you will get. How far back you can search depends on the tenant’s licensing and audit retention, so check your own settings before you rely on 90 days.

Step 5: Block external auto-forwarding at the tenant

Once you have cleaned up, close the door. Outbound spam policies in Exchange Online Protection control automatic forwarding to external addresses, covering both inbox rules and mailbox forwarding. According to Microsoft’s documentation on controlling external email forwarding, the default setting, Automatic, has meant different things for different tenants over the years, so Microsoft recommends setting it to On or Off explicitly.

Check the current value, then turn it off:

Get-HostedOutboundSpamFilterPolicy | Format-Table Name, AutoForwardingMode
Set-HostedOutboundSpamFilterPolicy -Identity Default -AutoForwardingMode Off

After this change, a forward to an outside address is blocked and the sender receives a non-delivery report with the code 5.7.520. Forwarding between users inside the tenant is not affected.

Some businesses do have a real need, such as an owner who wants a copy at a personal address, or an outside bookkeeper who receives supplier statements. Do not leave the whole tenant open for one exception. Create a separate outbound spam policy that allows forwarding, scope it to only the mailboxes that need it, and write down why. A shared mailbox that forwards to an outside accountant is easier to justify, and to review, than a dozen users each forwarding on their own.

Make it a quarterly check

Save the script from Steps 1 to 3 as a single file and run it every quarter, or whenever someone reports a strange email. Compare the new CSV with the last one; a rule that appeared since the last run on a mailbox that never had one is the line to read first. It fits naturally alongside the other recurring checks on our resources page, and it takes less time than the conversation you would have after a supplier payment goes to the wrong account.


Keep learning

Get the free Fundamental Security Concepts Checklist, plus one practical email a month with new tutorials, tools and threat notes for small business IT.