Skip to content
Menu

New Inbox Rules That Hide Mail

Reads user and shared mailbox inbox rules and alerts on suspicious rules within the first-seen window. It saves a local snapshot and changes nothing in the tenant.

New inbox rules that hide mail is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review New inbox rules that hide mail. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: Organization.Read.All; ExchangeOnlineManagement 3.1+, Exchange.ManageAsApp, Exchange admin role
Read-onlyReads, changes nothing

What It Does

The script connects to Exchange Online as your app and reads the inbox rules of every user and shared mailbox. It marks an enabled rule as suspicious when it deletes or permanently deletes messages, moves them to the RSS Feeds, RSS Subscriptions, Archive or Conversation History folder, marks them read, or has subject or body words invoice, payment or wire, plus any ExtraWords.

It keeps a local snapshot of suspicious rules and the previous snapshot beside it. A rule alerts while its first-seen time is less than NewWithinHours old, even if the rule was present on the previous run. Older rules stay listed without alerting.

The first run records every suspicious rule it finds as the starting point and reports them, so it ends ALERT if there are any. Review those once. Run it from the same computer each time, because the snapshot is a local file. Nothing is changed in the tenant.

It reads one mailbox at a time, so a large tenant can take several minutes. It does not read hidden inbox rules. If a mailbox's rules cannot be read, it warns and continues. If the ExchangeOnlineManagement module is missing, it ends SKIPPED.

Before You Run It

  • Install ExchangeOnlineManagement 3.1 or later, and give the app Exchange.ManageAsApp and a role that can read inbox rules, such as Exchange Administrator. Global Reader cannot.
  • Run it once and review what it reports. That first run is the baseline.
  • Always schedule it from the same computer, so the snapshot carries over.
  • Add ExtraWords for the phrases your clients' fraud usually uses.
  • Alert on exit 1 and act on the named mailbox quickly. A new hiding rule often means the account is compromised.

Type and Risk

  • Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: 1 to 10 minutes on a large tenant.
  • Example answer: "Suspicious inbox rules: 1 new; [user sign-in] rule 'x' (deletes; marks read)"
  • Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • TenantId: The client's tenant ID (a GUID) or domain such as contoso.onmicrosoft.com. Required.
  • ClientId: The app registration's Application (client) ID, a GUID. Required.
  • CertificateThumbprint: Thumbprint of the app's certificate, with its private key in LocalMachine\My or CurrentUser\My on this computer. Preferred. Leave empty to use the ClientSecret environment variable.
  • ExtraWords: More words that make a rule suspicious when they appear in its subject or body conditions, separated by comma, semicolon or new line (for example "remittance, bank details"). Default none.
  • NewWithinHours: A new suspicious rule keeps alerting for this many hours after it was first seen. Whole number, 1 to 720. Default 24.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

test-suspicious-inbox-rules.ps1 · 1074 lines · 59.9 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.