Outlook rules help users organize their mailboxes. Thanks to them, sieving spam from important messages can be more automatic and users mailboxes can look less chaotic. That is the bright side of Outlook rules. The less bright side is that users highly depend on them and every time there is an issue concerning the rules, admins find themselves to be in the eye of the storm. You can remain calm, though, as I will show you how to manage users’ Outlook rules using PowerShell. But first, you have to know the difference between the two types of those rules, to learn what you can do with PowerShell and what requires a direct intervention in the users’ email clients.
Server-side rules vs. client-side rules
Outlook rules can be either server-side or client-side. Understanding the differences between them is crucial for an admin, as the type determines when they are executed and which cmdlets can be used to manage them.
- Server-side rules: Their execution is performed entirely by the Exchange Server. They are enforced even when the user’s Outlook client is offline. You can use all cmdlets listed in the further part of the article. Mind that rules created in Outlook Web App are always server-side. Possible uses of These Outlook rules include:
- Change the priority of an email,
- Move an incoming message to another folder,
- Delete an email.
- Client-side rules: Those rules are executed only when Outlook is online, and the user is logged in. It will not work if an email is accessed from a different email client or a mobile device. What is more, it is impossible to use PowerShell to create or modify them with New-InboxRule and Set-InboxRule Using client-side rules, Outlook can e.g.:
- Move messages to a PST file,
- Play a specific sound when mail from a certain address arrives
- Mark a message as read
To check whether a rule is Server-side or Client-side, you can use Manage Rules & Alerts window in Outlook. Client-side rules have (client only) text added to their name, while server rules do not:
This Outlook window is the only place where you can check the type of an Outlook rule for sure. There is no certain way to determine this in Exchange Management Shell. It is true that, usually, client-side rules have a shorter description in EMS, as shown in the further part of the article, but it is hardly a foolproof way to determine a rule type.
Managing Outlook Rules with PowerShell
Starting from Exchange Server 2010, Microsoft has given the ability to use PowerShell for remote management of Outlook Rules. The cmdlets used for that purpose are as follows:
- Get-InboxRule, which previews the ruleset for a specified mailbox,
- New-InboxRule, which creates a new rule remotely,
- Enable-InboxRule and Disable-InboxRule used to turn rules on and off,
- Set-InboxRule, which modifies rules,
- Remove-InboxRule, which can be used to delete rules
Mind that successful execution of any cmdlet from the list above (apart from Get-InboxRule), removes all client-side rules created in Outlook for a user (Refer to this Microsoft article for more information).
Get-InboxRule
This cmdlet is primarily used to preview all rules set for a specific mailbox. In its basic form it looks like that:
Get-InboxRule -Mailbox <mailbox_name>
As you can see, each rule has its own, distinct RuleIdentity parameter. This parameter can be used to view its settings and description, like that:
Get-InboxRule –Mailbox <mailbox_name> -Identity <number> | FL
However, it is much easier and more efficient to search and view Outlook rules by their name and description:
Get-InboxRule –Mailbox <mailbox_user> | Select Name, Description | FL
Here, you can see the difference between server-side and client-side rules, mentioned before: In PowerShell, the description of the former is complete, while the description of the latter is much shorter, showing only the rule’s conditions:
Outlook:
Exchange Management Shell:
New-InboxRule
This cmdlet lets an Exchange Server administrator create a server-side rule remotely. It cannot be used to create a client-side rule. In other words, you can set up such a rule only using a user’s Outlook client.
I will show how to create two different rules using this cmdlet.
The following cmdlet creates a rule which moves messages which contain the word “spam” in the subject to the Junk E-mail folder:
New-InboxRule -Name "Move to Spam" -Mailbox j.doe -MoveToFolder '[email protected]:\Junk Email' -SubjectContainsWords "Spam" -StopProcessingRules $True
Mind that you can combine it with a mail flow rule which adds the word ”spam” to the email subject when meeting certain conditions.
The next cmdlet generates a rule which moves emails received before April 15, 2017, from Inbox to the Archive subfolder:
New-InboxRule -Name "To archive" -Mailbox [email protected] -MoveToFolder "[email protected]:\Inbox\Archive" -ReceivedBeforeDate "04.15.2017"
Enable-InboxRule, Disable-InboxRule,
You can use them to turn Outlook rules on and off
You can check which rules are enabled using Get-InboxRule:
Get-InboxRule –Mailbox <mailbox_name>
Disabling and enabling a rule works in the same way:
Disable-InboxRule -Identity <rule_name> -Mailbox <mailbox_name>
Enable-InboxRule -Identity <rule_name> -Mailbox <mailbox_name>
Set-InboxRule
This cmdlet lets you modify any server-side rule. It is a good practice to check the detailed description of the rule you want to modify. You can do it with the previously described Get-InboxRule cmdlet:
Get-InboxRule –Identity <rule_name> Mailbox <mailbox_user> | Select Name, Description | FL
Let’s change its conditions so that it reacts to the word “spam” included in the email body, instead of its subject:
Set-InboxRule -Identity <rule_name> -Mailbox <mailbox_name> -BodyContainsWords "spam" -SubjectContainsWords $nule
Remove-InboxRule
The last cmdlet irreversibly removes any rule you specify from a mailbox.
Remove-InboxRule -Identity <rule_name> -Mailbox <mailbox_name>
Common problems with Outlook rules
Outlook rules give users the ability to control and organize their mailboxes content. At the same time, those rules generate problems with the messages. Below are the most common problems Exchange Server admins come across:
Rules conflict
Conflicts usually occur when more than one rule applies to an incoming email. For example:
John receives a message from Tony with the subject Important. John’s Outlook has two rules which apply to this email. The first one should move all messages from Tony to the Co-workers subfolder. The second rule is supposed to move emails with the subject Important to the Important e-mails subfolder.
If both rules are the client-side type, they will be executed according to the priority they have (you can check rules’ priority using Get-InboxRule -Mailbox <mailbox_name>). In this situation, the message from Tony will go to the Co-workers subfolder and the second rule will not be enforced due to the conflict.
But the real problem begins, when server-side and client-side rules mix. When the Outlook client is offline, server-side rules will be executed first, even if they have a lower priority. Let’s go back to the example above. If the first rule is client-side and the second one is server-side, the message will be moved to different folders, depending on whether the client is running or not.
Forwarding rules
The ability to create such rules often leads to emails either being duplicated, going missing or going to a wrong recipient. Such problem may occur if a user forgets that before going on vacation they set a rule which forwards their correspondence to someone else (and it happens a lot).
You can solve such problems using logs from Get-MessageTracingLog cmdlet. You can find such anomalies by looking for MAILBOXRULE entry under the Source header:
Then you can filter this MAILBOXRULE event:
And finally, use Get-InboxRule rule to learn whose Rule is responsible for the issue:
Outlook Rules in a company
Apart from helping individual users, Outlook rules can also be used to organize workflow of a whole company. For example, you could remotely create subfolders in users’ Inbox folders, and then create a rule which moves emails from an internal company application to the newly created folders. It will help keep the correspondence well organized throughout a whole company.
First, you can use an EWS-based script to create folders in your users’ mailboxes.
Next, using New-InboxRule, you can create a rule which will move the messages of your choosing to the newly created subfolders.
Note that this is a single example of how Outlook rules can be used in a company.
No doubt, Outlook rules can come in handy in many situations. At the same time, managing them along with mail flow rules can be quite overwhelming from an Exchange Server Administrator’s perspective. In some cases, a multitude of those rules can cause a major disturbance in mail flow of the company. To make an admin’s job much easier, you can use Exchange Rules Pro. One of its many features is that it helps with managing transport rules and ensuring that mail flow is not disturbed.
HELLO, can anyone deploy an outlook client rule to a set of users which automatically prints emails received from a user when they arrive, this rule would be in powershell or in VB or GPO…?. I don’t can’t find my happiness :(
client Outlook 2021 and Exchange 2019 on promise
Is it possible to trigger (run it once) a rule via powershell ?
Unfortunately, there’s no such option at the moment. The option to instantly trigger rules like that is reserved for Outlook.
The Outlook desktop version supports action “have server reply using a specific message” which allows to create server-side rule to emulate Out-of-office functionality.
In the description of New-InboxRule as well Set-InboxRule I did not find corresponding action.
Is is possible to create such rule through Exchange PowerShell?
Pay attention that although it is server-side rule Outlook Web App shows such rule as “This rule can’t be edited or viewed in Outlook on the web”
As far as I know, this action can’t be configured with PowerShell.
Is it possible to export all Office 365 users’ rules, including those setup via Outlook Web App?
We had a user account compromised, and he only had the 2 rules he previously created showing in Outlook, but when logged into OWA he had a 3rd rule, created by the hacker.
Take a look at my second article on Outlook/Inbox rules. There is a method to export all rules, including the ones from OWA/Outlook on the web.
One of the most effective approaches for automating manual tasks is to use Outlook rules. If you get a lot of mail from multiple vendors, for example, you may now automate the sorting process. This can save you a lot of time, and all you have to do is set up an automatic rule to send them to their appropriate folders.
You may quickly build rules and tweak them according to your needs. It is also not a difficult chore to manage rules. This entire procedure can make your daily tasks much easier and more efficient.
I discovered something very interesting about inbox rules. I have been able to identify client side rules by using this code snippet:
Get-InboxRule -Mailbox | where {$_.supportedbytask -eq $false} |select Identity, Name
It makes me wonder what supported by task means? I have scoured the internet high and low for an answer. Anybody have any ideas?
Hi, How do I create a server-side O365 rule that will prevent an email that includes certain text in the subject from having any client-side rules run against it? May users have setup folder rules for a spammy 3rd party system that’s blasting their inboxes, but some of these emails are important and shouldn’t be missed. We want to prevent these specific emails from getting managed by the local client rules.
You could create an inbox rule with the highest priority for those specific emails which would mark them as High importance, and add -StopProcessingRules $true. If users tamper with the rule, you can either remove their rules with PowerShell, or use the Set-OwaMailboxPolicy cmdlet with -RulesEnabled $false to make them unable to edit inbox rules at all.
Hi
Great docs ….
Your link “Create folders in users’ mailboxes” seems dead
I am also looking for the command to add a rule, for moving messages to a specific folder depending of a header string, but globally for all users of a specific OU
Any idea?
Olivier
Hi,
Thanks for mentioning the link – it seems the target article was killed. I’ll add a new one as soon as I find some time to test another script or write one on my own.
When it comes to adding a new rule, you could use the -HeaderContainsWords parameter. The easiest way to apply it to all members of a certain OU, would be to get those members into a variable and use the ForEach cmdlet to loop through them with the New-InboxRule command.
Hi
Is it possible to add a rule to all Calendar invitations?
Like, when the VP receives a Calendar invitation , it will be automatically moved to a folder.
You should be able to apply a rule for invitations by using the
-MessageTypeMatches Calendaring
attribute. To move such message to a folder, use the -MoveToFolder attribute.Is there any way, for all incoming mails, we can disable link in mail and convert it to text ?
For a single user, you can go to Email Security options in the Trust Center and check the option to Read all standard mail in plain text. I don’t think there is such action available in Inbox rules.
Hi,
I want to create a rule with powershell on limited accounts that when the user is sending an email to outside the Company domain, the email will also be forwarded to a public folder.
Kindly can you help.
Thanks
I wouldn’t use Outlook rules for that – it will be much simpler to use mail flow rules instead. Here is an article on mail flow rules. If you have any trouble setting up the rule, let me know.
HI,
I want to create a rule with VBA script. Is it possible through powershell. I tried searching for parameters of New-InboxRule but could not find anything.
Hi Aastha,
As far as I know, you can create rules using VBA or PowerShell, but you cannot run VBA script with the New-InboxRule cmdlet. What exactly are you trying to achieve?
Hi!
Is there a way to create a rule to all mailboxes (and that is also automatically applied to users created after the creation of the rule), that moves emails with ‘[SPAM]’ in the start of the subject to the ‘Junk e-mail’ folder, that also is applied to emails forwarded from Distribution groups?
Thanks in advance!
Hi Ian,
You cannot apply an inbox rule automatically to every new mailbox, unless you include the New-InboxRule cmdlet in the user creation/onboarding script.
You can achieve a similar result by creating a mail flow rule which is applied to all messages with [SPAM] in the subject and changes such messages’ spam confidence level to the highest value.
I am able to run
Disable-InboxRule “[email protected]\”
To disable rules, but some rules will not disable and I receive an error message “Your email server doesn’t support this inbox rule”
We are using O365. I have determined that the above command only disabled the server side rules.
Any way to disable the client side rules as well?
Any help is appreciated.
Hi Mark,
You cannot disable client-side rules with PowerShell, it’s not possible, yet. However, Remove-InboxRule should work fine with both rule types.
Additionally, all related docs sites (like this one) clearly state that:
“When you create, modify, remove, enable, or disable an Inbox rule in Exchange PowerShell, any client-side rules created by Microsoft Outlook are removed”
Robert we utilize office365. Is there a way to rename a users rule within shell?
Hello Brandon,
Yes, you can rename a user’s rule with PowerShell:
Set-InboxRule *rule identity* -name "*changed name*"
so, in my test environment, I can change teh rule that User A has with:
Set-InboxRule usera\526313306860814338 -Name "New rule name"
To determine the rule’s identifier (and to check if its name has changed afterwards), you can run:
Get-InboxRule -Mailbox *user's mailbox*
Thank you for the in-depth article Adam, definitely intuitive.
I have found with many of my clients utilizing Office 365, the command get-inbox rule doesn’t actually return anything. For example;
get-mailbox kxxxxxxxx | get-inboxrule
The operation couldn’t be performed because ‘Keith xxxxxxxx’ couldn’t be found.
+ CategoryInfo : NotSpecified: (:) [Get-InboxRule], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=YTBPR01MB2526,RequestId=cb01e721-57cd-4019-bb97-21f850c8171c,TimeStamp=10/15/201
9 4:13:36 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 4C35CD74,Microsoft.Exchange.Management.Re
cipientTasks.GetInboxRule
+ PSComputerName : outlook.office365.com
While I would take this as there are no inbox rules, found this user had several inbox rules that could be viewed through https://outlook.office.com/owa but not visible in their Outlook desktop app.
We do have full access as it was provided to the mailbox previously through add-mailboxpermission kxxxxxxxx -user admin -accessrights fullaccess -automapping $false
In this circumstance, do you know how to make those inbox rules visible to the global admin for the Office 365 tenant?
Thank you,
Clayton
solut Ltd
Hi Clayton,
Unfortunately, it will not work that way, as the default value for the Get-InboxRule is not -Mailbox – it is -InboxRuleIdParameter. To make long story short, if you need to use get-mailbox, use either of the following syntax:
get-inboxrule -mailbox (get-mailbox meganb).UserPrincipalName
– for a single mailbox$mailboxes=(get-mailbox).UserPrincipalName;foreach ($mailbox in $mailboxes) {get-inboxrule -Mailbox $mailbox}
– for all mailboxes. If a mailbox does not have any rules configured, the cmdlet will not return anything for the mailbox. So no errors should appear.how can I remove a specific rule form multiple mailboxes
As long as the specific rule has the same name at each mailbox, you can use the following syntax:
$mailboxes = import-csv *CSV with the list of mailboxes*
foreach($mailbox in $mailboxes) {Remove-InboxRule -Mailbox $mailbox -Identity *rule name*}
Instead of import-csv, you can use get-mailbox with the right parameters. It all depends on where you keep the list of those “multiple mailboxes”.
A word of warning – Before running this cmdlet on production, create a test user, add a few Outlook rules and use the cmdlet to delete one of them. Then, verify if the other rules are there and work as expected.
Is it possible to see the date when a rule was created?
Regards,
Robert
Hi Robert,
Unfortunately, Get-InboxRule does not retrieve the rule creation date. You might be able to find the date using mailbox audit logs, but you would have to enable them before trying to get any information.
@Adam
We use Public folders to auto-archive sent emails based on what job number is in the subject field. Each user now has to individually set those rules in case it’s them sending the email that needs to be archived. I was hoping to find a way to centrally push out those rules to the clients or otherwise manage them centrally on the server. I’ll have another look at inbox rules but I don’t think it applies here.
You could use New-InboxRule with -SubjectContainsWords and -MoveToFolder attributes to distribute rules with specific job numbers to all employees who use public folders. It would work, and it would be less problematic than each user doing it manually. If that does not work for you, you could also use the export/import feature from within Outlook. It would make things at least a bit less problematic.
Personally, I would try setting the inbox rule directly for the public folder. Though I’m not entirely sure how exactly your auto-archiving and job number feature works, so I can’t tell if that’s the best solution for you.
Does the Powershell commands work for regular users, or is it only possible for Exchange admins?
If it works for users which Powershell module do I have to install? Because Get-InboxRule is not available in a regular Powershell.
Hi Robert,
To run inbox-rule-related cmdlets, you need to have some permissions. To find out which permissions exactly, simply run the following: get-managementrole -cmdlet get-inboxrule. All the cmdlets I mention, require the Exchange PowerShell module and connection to the Exchange Server (or using Exchange Management Shell).
How can I manage outbox rules? There doesn’t seem to be a Get-OutboxRule cmdlet available..
What do you mean by outbox rules? If you mean rules that apply to outgoing messages, those are still inbox rules. Unfortunately, those rules are client-side, so you will not be able to do much managing via PowerShell. If you want to manage outgoing emails, you should use transport rules (Get-TransportRule).
Do you have a tool to export and import inbox rules across inter-tenant migrations?
Hello Allen,
I’m afraid that the only available way to export and import inbox rules is the built-in Outlook manual tool available in Rules’ Options.
It seems rather odd that this isn’t exposed natively, but do you happen to know how to discover WHEN an inbox rule was created?