🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

Using New-TransportRule to Create Microsoft Exchange Mail Flow Rules

In Microsoft Exchange Online, mail flow rules—also known as transport rules—are essential for controlling and automating how email is processed. These rules allow administrators to apply conditions and actions to messages that pass through the transport pipeline.

While Graph PowerShell continues to evolve, it does not yet support the creation of mail flow rules. For now, you must use Exchange Online PowerShell to manage mail flow at this level.

This article dives into the New-TransportRule cmdlet, illustrating how to create custom rules with real-world examples, practical tips, and troubleshooting guidance.


Cmdlet Syntax

New-TransportRule -Name  [-Comments ] [-Priority ] [-Enabled <$true | $false>] [-SentTo ] [-From ] [-SenderDomainIs ][-RedirectMessageTo ] [-RejectMessageReasonText ][-SetAuditSeverity ][-Other Parameters...]

You must be connected to Exchange Online using:

Connect-ExchangeOnline

Usage Examples

Example 1: Redirect CEO Emails to Another Address

New-TransportRule -Name "Redirect CEO Emails" ` -SentTo "samadmin@7xh7fj.onmicrosoft.com" ` -RedirectMessageTo "dexter@7xh7fj.onmicrosoft.com"

This rule redirects all emails sent to the CEO's mailbox to another address, which can be helpful for delegation or monitoring.


Example 2: Block All Emails from Example.com Domain

New-TransportRule -Name "Block Example.com Emails" ` -SenderDomainIs "example.com" ` -RejectMessageReasonText "Emails from gmail.com are not accepted."

This rule blocks any incoming emails from senders using example.com and returns a rejection notice to the sender.


Cmdlet Tips

  • You can stack conditions and actions to make more complex rules (e.g., sender domain + subject match).
  • Use -Priority to set rule order explicitly.
  • Always test your rule in a controlled scenario before deploying it broadly.
  • Use Get-TransportRule to verify rule creation and settings.
  • Disable a rule temporarily using Disable-TransportRule -Identity "".

Possible Errors & Solutions

Error Cause Solution
New-TransportRule is not recognized Not connected to Exchange Online Run Connect-ExchangeOnline
The transport rule name already exists Duplicate rule name Use a unique name or modify existing rule
Invalid parameter Typo or unsupported combination Use Get-Help New-TransportRule -Full for guidance
SenderDomainIs requires a valid domain Domain not formatted correctly Use values like "domain.com" without wildcards

Use Cases

  • Security: Block specific domains or IPs known for phishing.
  • Compliance: Redirect sensitive emails for auditing.
  • Productivity: Apply disclaimers, tags, or auto-responses.
  • Routing: Automatically forward emails based on recipient or subject.
  • Delegation: Redirect or copy important roles' emails to backups.

Conclusion

The New-TransportRule cmdlet is a powerful way to manage mail flow policies in Microsoft Exchange Online. Whether you're automating redirection, filtering senders, or enforcing company email policies, this cmdlet has you covered.

As Graph PowerShell matures, we may see support for these configurations in the future—but for now, Exchange PowerShell remains the definitive tool for managing transport rules.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

© m365corner.com. All Rights Reserved. Design by HTML Codex