How to Use Get-MgUserMailFolderMessageRule to Fetch Message Rules?

Managing mailbox rules is crucial for automating email workflows, and Microsoft Graph PowerShell provides a simple way to access these rules -- using Get-MgUserMailFolderMessageRule cmdlet. In this guide, you'll learn how to fetch, view, and filter message rules effectively.


What is Get-MgUserMailFolderMessageRule?

Get-MgUserMailFolderMessageRule is a Microsoft Graph PowerShell cmdlet used to retrieve the message rules (also known as inbox rules) associated with a specific mail folder in a user's Microsoft 365 mailbox.

Each rule defines an action for incoming messages, such as moving emails to a folder, forwarding emails, or marking them as read.


Why Use Get-MgUserMailFolderMessageRule?

  • Automation: Quickly retrieve existing rules to audit or manage email workflows.
  • Troubleshooting: Identify conflicting or redundant message rules causing email misrouting.
  • Reporting: Create reports on user-defined email rules across mailboxes.
  • Bulk Management: Fetch and review rules across multiple users in bulk.

Cmdlet Syntax

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

Parameters:

  • UserId: The UPN (email address) or ID of the mailbox owner.
  • MailFolderId: The ID of the specific mail folder.
  • ExpandProperty: (Optional) Expands related entities inline.
  • Property: (Optional) Selects specific properties to return.

Note: To fetch MailFolder IDs, use the Get-MgUserMessageFolder cmdlet.


Usage Examples

Example 1: Fetch All Message Rules

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

This command retrieves all message rules in the specified mail folder for the user.

Example 2: Fetch a Single Message Rule

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

This fetches a specific message rule based on its MessageRuleId.

Example 3: Filter Message Rules (Only Enabled Rules)

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

This retrieves only the rules that are currently active (enabled).

Note: Use Get-MgUserMessageFolder cmdlet to fetch the MailFolder IDs before using Get-MgUserMailFolderMessageRule.


Frequently Asked Questions

  • Can I retrieve rules from folders other than Inbox?
    Yes! Provide the correct MailFolderId for any folder where you want to retrieve message rules.
  • What happens if I provide an incorrect MailFolderId?
    You'll receive an error stating that the folder was not found.
  • Can I modify or delete message rules using this cmdlet?
    No. Get-MgUserMailFolderMessageRule only retrieves rules. Use Update-MgUserMailFolderMessageRule or Remove-MgUserMailFolderMessageRule for modifications.
  • How can I find the MessageRuleId?
    Run the command without the -MessageRuleId parameter to list all rules. Each rule will have an Id you can reference.

Use Cases

  • Auditing user mail rules to ensure compliance.
  • Identifying inactive or conflicting rules that might cause email mismanagement.
  • Generating reports for mailbox rule configurations.
  • Troubleshooting email delivery issues caused by unexpected rule behavior.

Conclusion

The Get-MgUserMailFolderMessageRule cmdlet offers a straightforward method to retrieve and audit message rules from a user's mailbox. Whether you're troubleshooting email delivery, automating audits, or managing mailbox workflows, this cmdlet gives you full visibility into how incoming messages are handled.

Combine it with other Microsoft Graph PowerShell cmdlets to create powerful scripts for email governance in your Microsoft 365 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