How to Use Get-MgUserMailFolderMessageRule to Fetch User Mail Folder Message Rules?

Email message rules help users organize their inboxes by automatically taking actions on incoming mail, such as moving, deleting, or categorizing messages. As an administrator or support engineer, being able to view these rules can help troubleshoot mail flow issues or ensure compliance.

In this article, we'll cover how to use the Get-MgUserMailFolderMessageRule cmdlet to fetch message rules for a user's mail folder using Microsoft Graph PowerShell.


What is Get-MgUserMailFolderMessageRule?

Get-MgUserMailFolderMessageRule is a Microsoft Graph PowerShell cmdlet that allows administrators to retrieve message rules set on a specific mail folder (like the Inbox) for any user within their Microsoft 365 tenant.

This is particularly useful when diagnosing issues like:

  • Messages not arriving in the Inbox
  • Emails being automatically moved or deleted
  • Unintended rules impacting mail delivery

Why Use Get-MgUserMailFolderMessageRule?

Here’s why this cmdlet is incredibly handy:

  • Troubleshooting: Find out why important emails are being routed elsewhere.
  • Audit & Review: View custom rules configured by users or policies.
  • Automation: Use in scripts to review, log, or report rule configurations across multiple mailboxes.
  • Compliance: Ensure users don’t have message rules that violate company policies.

Cmdlet Syntax

Get-MgUserMailFolderMessageRule -UserId <String> -MailFolderId <String> [-MessageRuleId <String>]

Parameters:

  • UserId: The UPN (e.g., user@domain.com) or object ID of the user.
  • MailFolderId: The folder where rules exist, commonly "Inbox".
  • MessageRuleId (optional): Use this to get details of a specific rule.

Usage Examples

Fetch All Message Rules

You can retrieve all message rules set for a user's Inbox using either of the two formats:

Get-MgUserMailFolderMessageRule -MailFolderId Inbox -UserId samadmin@7xh7fj.onmicrosoft.com

Or, if you prefer using the folder ID:

Get-MgUserMailFolderMessageRule -UserId "user@example.com" -MailFolderId "AAMkAGI2TgAAA="

These commands return a list of all rules, including their conditions, actions, and whether they're enabled or not.

Fetch a Single Message Rule

To retrieve a specific rule, you’ll need the rule ID along with the folder ID:

Get-MgUserMailFolderMessageRule -UserId "user@example.com" -MailFolderId "AAMkAGI2TgAAA=" -MessageRuleId "AQMkAGI2TgAAA="

This gives you all the details of that particular rule.

Filter Message Rules

Want to find only enabled rules?

Get-MgUserMailFolderMessageRule -UserId "user@example.com" -MailFolderId "AAMkAGI2TgAAA=" | Where-Object { $_.isEnabled -eq $true }

You can also filter on other properties like DisplayName, Actions, or Conditions.


Frequently Asked Questions

Can I fetch rules for folders other than Inbox?

Yes, but you’ll need the MailFolderId for those folders. You can get them using Get-MgUserMailFolder.

Do I need special permissions to run this cmdlet?

Yes. You need Mail.Read or Mail.ReadWrite delegated permissions, or app-only permissions like Mail.ReadBasic.All.

What if the folder has no rules?

The cmdlet will return an empty result — meaning there are no message rules set on that folder.


Use Cases

  • Email Troubleshooting: Determine why emails are being moved to unexpected folders.
  • Compliance Checks: Ensure sensitive mail is not being auto-forwarded externally.
  • Automation Scripts: Loop through mailboxes to generate reports on rules.
  • Security Audits: Monitor auto-delete rules that might be hiding phishing or spam.

Conclusion

The Get-MgUserMailFolderMessageRule cmdlet is an essential tool for administrators who manage mail flow and mailbox rules in Microsoft 365. With the ability to inspect rules folder-by-folder and user-by-user, it helps ensure that messages behave as expected and that mailbox configurations align with your organizational policies.

Once you get familiar with it, you’ll find it invaluable for diagnosing quirky mail behaviors and maintaining a well-governed email environment.

Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex