Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / Exchange / Managing Exchange Mailbox Inbox Rules with PowerShell

August 29, 2019 ExchangePowerShell

Managing Exchange Mailbox Inbox Rules with PowerShell

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.

Contents:
  • Client-Side and Server-Side Outlook Rules
  • Get-InboxRule: How to Show User Inbox Rules in the Exchange Mailbox?
  • How to Search for the Inbox Rules in the User Mailboxes?
  • How to Create a Outlook Inbox Rule Using PowerShell?
  • How to Disable and Remove an Outlook Inbox Rule?

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 ZenossAlerttoHelpdesk -Mailbox NYadmin -SubjectContainsWords "Zenoss 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 secretary@woshub.com:

New-InboxRule -Mailbox john.doe –name SecretaryRule -From secretary@woshub.com –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

0 comment
0
Facebook Twitter Google + Pinterest
previous post
Test-NetConnection: Check for Open/Closed Ports from PowerShell
next post
How to Show/Hide All User Accounts from Login Screen in Windows 10?

Related Reading

Checking User Logon History in Active Directory Domain...

January 22, 2021

Windows 10: No Internet Connection After Connecting to...

January 13, 2021

Updating the PowerShell Version on Windows

December 24, 2020

Restoring Deleted Active Directory Objects/Users

December 21, 2020

Auditing Weak Passwords in Active Directory

December 14, 2020

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • How to Configure and Connect an iSCSI Disk on Windows Server?

    January 26, 2021
  • Preparing Windows for Adobe Flash End of Life on December 31, 2020

    January 22, 2021
  • Checking User Logon History in Active Directory Domain with PowerShell

    January 22, 2021
  • How to Disable/Remove Thumbs.db File on Network Folders in Windows?

    January 21, 2021
  • MS SQL Server 2019 Installation Guide: Basic Settings and Recommendations

    January 19, 2021
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine

    January 15, 2021
  • Windows 10: No Internet Connection After Connecting to VPN Server

    January 13, 2021
  • Updating the PowerShell Version on Windows

    December 24, 2020
  • How to Enable and Configure User Disk Quotas in Windows?

    December 23, 2020
  • Restoring Deleted Active Directory Objects/Users

    December 21, 2020

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • New-MailboxRepairRequest: Fixing Corrupted Mailboxes in Exchange 2016/2013/2010
  • Configuring Anti-Spam Protection on Exchange 2013, 2016 – RBL Providers
  • How to Configure DKIM on Exchange Server 2010/2013
  • Outlook 2016: Manual Setup Exchange Account
  • How to Import and Export Mailbox to PST in Exchange 2016/2013/2010?
  • Fix: Outlook 2016/2013 Always Starts in Offline Mode
  • Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server
Footer Logo

@2014 - 2018 - Windows OS Hub. All about operating systems for sysadmins


Back To Top