Skip to main content
Exchange

Managing Exchange Mailbox Inbox Rules with PowerShell

By January 8, 2020No Comments

Outlook rules allow the users to create different conditions to process the incoming email messages. You can move emails from specific senders that meet certain criteria to a folder you want, mark emails as important, forward the email messages to another user, etc. Usually users create and manage their rules in Outlook graphic interface. In Exchange 2010/2013/2016, an administrator can manage inbox rules in user mailboxes through the PowerShell console. In this article we’ll look on how to add, delete, disable or modify Outlook inbox rules via the Exchange Management Shell.

Client-Side and Server-Side Outlook Rules

An Exchange administrator should differ between client-side and server-side Outlook rules.

  • Server-side Outlook rules work on the side of the server when receiving an email. They always work, it doesn’t matter if the user is running Outlook client or not (rules created using Outlook Web App are always server-side). The following rules can be applied on the Exchange server side: marking an email as important, moving an e-mail to another mailbox folder, deleting a message, forwarding an e-mail to another email address;
  • Client-side rules are applied only if the Outlook client has been started: e. g., to mark an e-mail as read, to move email message to local PST file, to display a notification or play a sound. You cannot manage these rules through Exchange PowerShell. These rules have ‘client-only’ status in Outlook interface.
list of server-side and client-side rules in outlook

Get-InboxRule: How to Show User Inbox Rules in the Exchange Mailbox?

To display the list of rules in the user Exchange mailbox, start the EMS console and run this PowerShell command:

Get-InboxRule –Mailbox john.doe

managing outlook mailbox rules via powershell

As you can see, the name, status (Enabled: True/False), priority and RuleIdentity of each rule are displayed.

You can see the detailed information about the specific Inbox rule by specifying its name:

Get-InboxRule -Mailbox john.doe -Identity "HelpDesk"| fl

Usually you can understand the contents of the rule by its description:

Get-InboxRule -Mailbox john.doe -Identity "HelpDesk "| Select Name, Description | fl

Get-InboxRule for exchnage mailbox

How to Search for the Inbox Rules in the User Mailboxes?

In some cases, an administrator has to find certain rules in a user’s mailbox. For example, you have to find all rules that delete emails:

Get-InboxRule -Mailbox john.doe | ?{ $_.DeleteMessage }

Also, there may be a scenario, when the information security department asks you to find all automatic email forwarding rules in all user mailboxes of your company:

foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.ForwardTo} | fl MailboxOwnerID,Name,ForwardTo >> C:\PS\All_Mailbox_Forward_Rules.txt }

The resulting text file will contain the list of mailboxes, names of forwarding rules and the recipients to whom these e-mails are forwarded.

How to Create a Outlook Inbox Rule Using PowerShell?

You can create a new rule for Outlook inbox using the New-InboxRule Exchange cmdlet. For example, you want to forward all e-mails containing certain keywords in the subject to another user. Run this command:

New-InboxRule -Name ContosoAlerttoHelpdesk -Mailbox ContosoAdmin -SubjectContainsWords "Contoso HW Alert" -ForwardTo "Helpdesk"

This rule will apply red category and higher importance level for all emails with the keywords ‘Annual meeting’ in the subject from [email protected]:

New-InboxRule -Mailbox john.doe –name SecretaryRule -From [email protected] –SubjectContainsWords “Annual meeting" -ApplyCategory {Red Category} -MarkImportance 2

Let’s create a rule that moves all emails with ‘Casino’ in the subject to the Junk Email folder for all users in the specific Active Directory OU.

$mbxs = Get-mailbox -organizationalUnit Managers
$mbxs | % { }
$mbxs | % { New-inboxrule -Name SpamMail -mailbox $_.alias -subjectcontainswords “[casino]” -movetofolder “$($_.alias):Junk Email” }

You can display the list of all available properties, conditions and actions to be used in the Exchange rules as follows:

Get-InboxRule -Mailbox john.doe | get-member

TypeName: Microsoft.Exchange.Management.RecipientTasks.InboxRule
ApplyCategory
BodyContainsWords
CopyToFolder
DeleteMessage
Description
Enabled
FlaggedForAction
ForwardAsAttachmentTo
ForwardTo
From
FromAddressContainsWords
FromSubscription
HasAttachment
HasClassification
HeaderContainsWords
Identity
InError
IsValid
MailboxOwnerId
MarkAsRead
MarkImportance
MessageTypeMatches
MoveToFolder
MyNameInCcBox
MyNameInToBox
MyNameInToOrCcBox
MyNameNotInToBox
Priority
ReceivedAfterDate
ReceivedBeforeDate
RecipientAddressContainsWords
RedirectTo
RuleIdentity
SendTextMessageNotificationTo
SentOnlyToMe
SentTo
StopProcessingRules
SubjectContainsWords
SubjectOrBodyContainsWords
SupportedByTask
WithImportance
WithinSizeRangeMaximum
WithinSizeRangeMinimum
WithSensitivity

To change an Outlook rule, use the Set-InboxRule cmdlet, e. g.:

Set-InboxRule -Mailbox john.doe –identity SecretaryRule -FromAddressContainsWords {gmail.com}

Tip. The size of the rules in a Microsoft Exchange mailbox is limited. In Exchange 2003 it is 32 KB, and in Exchange 2016/2013/2010 it is 64 KB. If this error appears when trying to edit rules:

One or more rules could not be uploaded to Exchange server and have been deactivated. This could be because some of the parameters are not supported or there is insufficient space to store all your rules.

You can change the rules quota (RulesQuota) to 256 KB using this command:

Set-Mailbox -identity john.doe -RulesQuota 256Kb

How to Disable and Remove an Outlook Inbox Rule?

To disable an Outlook inbox rule, enter this command:

Disable-Inboxrule –Mailbox john.doe -Identity “SecretaryRule”

At the same time its status (Enabled) is changed to False, and it is no longer applied to the incoming email messages.

To completely remove an Inbox rule, run this command:

Remove-Inboxrule –Mailbox john.doe -Identity SecretaryRule

The command will prompt you to confirm it, and you just have to press Y. To remove all rules in a user mailbox, run the following:

Get-inboxrule -mailbox john.doe | disable-inboxrule

Leave a Reply