Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 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
1
Facebook Twitter Google + Pinterest
previous post
Test-NetConnection: Check for Open/Closed Ports from PowerShell
next post
Microsoft KMS Volume Activation FAQ

Related Reading

Using Previous Command History in PowerShell Console

January 31, 2023

How to Install the PowerShell Active Directory Module...

January 31, 2023

Finding Duplicate E-mail (SMTP) Addresses in Exchange

January 27, 2023

How to Disable or Uninstall Internet Explorer (IE)...

January 26, 2023

How to Delete Old User Profiles in Windows?

January 25, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Configure User’s Folder Redirection with Group Policy

    February 3, 2023
  • Using Previous Command History in PowerShell Console

    January 31, 2023
  • How to Install the PowerShell Active Directory Module and Manage AD?

    January 31, 2023
  • Finding Duplicate E-mail (SMTP) Addresses in Exchange

    January 27, 2023
  • How to Delete Old User Profiles in Windows?

    January 25, 2023
  • How to Install Free VMware Hypervisor (ESXi)?

    January 24, 2023
  • How to Enable TLS 1.2 on Windows?

    January 18, 2023
  • Allow or Prevent Non-Admin Users from Reboot/Shutdown Windows

    January 17, 2023
  • Fix: Can’t Extend Volume in Windows

    January 12, 2023
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11

    January 11, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Configuring Anti-Spam Protection on Exchange 2013, 2016 – RBL Providers
  • New-MailboxRepairRequest: Fixing Corrupted Mailboxes in Exchange 2016/2013/2010
  • How to Configure DKIM on Exchange Server 2010/2013
  • Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server
  • How to Import and Export Mailbox to PST in Exchange 2016/2013/2010?
  • How to Blacklist/Block Sender Domain or an Email Address on Exchange?
Footer Logo

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


Back To Top