Adding, modifying, and removing server-side inbox rules
Exchange 2010 introduces a new set of cmdlets that can be used to manage server-side inbox rules for mailboxes in your organization. For the first time, we have the ability to add, remove, update, enable, and disable the inbox rules for mailboxes from within the Exchange Management Shell. This new functionality allows administrators to quickly resolve mailbox issues related to inbox rules, and allows them to easily deploy and manage inbox rules in bulk using just a few simple commands. In this recipe, you'll learn how to work with the inbox rules cmdlets in Exchange 2010.
How to do it...
- To create an inbox rule, use the
New-InboxRule
cmdlet:New-InboxRule -Name Sales -Mailbox dave ` -From sales@contoso.com ` -MarkImportance High
- You can change the configuration of an inbox rule using the
Set-InboxRule
cmdlet:Set-InboxRule -Identity Sales -Mailbox dave -MarkImportance Low
- Use the
Enable-InboxRule
andDisable-InboxRule
cmdlets to turn a rule on or off:Disable-InboxRule -Identity Sales -Mailbox dave
- The
Get-InboxRule
cmdlet will return all of the server-side rules that have been created for a specified mailbox. The output from the command is shown in the following screenshot: - To remove an inbox rule, use the
Remove-InboxRule
cmdlet:Remove-InboxRule -Identity Sales -Mailbox dave -Confirm:$false
How it works...
Inbox rules are used to process messages sent to a mailbox based on a certain set of criteria, and to then take an action on that message if the condition is met. In the previous example, we created an inbox rule for the mailbox that would mark messages from the sales@contoso.com
address with high importance. The New-InboxRule
cmdlet provides a number of rule predicate parameters that allow you to define the conditions used for the rules you create.
Let's take a look at another example. Say that we want to create a rule that will check the subject or body of all incoming messages for a certain keyword. If there is a match, we'll send the message to the deleted items folder:
New-InboxRule -Name "Delete Rule" ` -Mailbox dave ` -SubjectOrBodyContainsWords "Delete Me" ` -DeleteMessage $true
In addition to conditions and actions, we can also add exceptions to these rules. Consider the following example:
New-InboxRule -Name "Redirect to Andrew" ` -Mailbox dave ` -MyNameInToOrCcBox $true ` -RedirectTo "Andrew Castaneda" ` -ExceptIfFrom "Alfonso Mcgowan" ` -StopProcessingRules $true
In this example, once again we're creating an inbox rule in Dave's mailbox. The condition MyNameInToOrCcBox
is set to $true
so that any message with the mailbox name in the To
or CC
fields will be processed by this rule. The action is the RedirectTo
setting, and that will redirect the message to Andrews's mailbox, except if the message was sent from Alfonso's mailbox. Finally, the -StopProcessingRules
parameter is set to $true
, meaning that, once this rule is processed, Exchange will not process any other rules in this mailbox. The -StopProcessingRules
parameter is an optional setting and is provided to give you another level of flexibility when it comes to controlling the way the rules are applied.
Note
It's important to note that when you add, remove, update, enable, or disable server-side rules using the *-InboxRule
cmdlets, any client-side rules created by Outlook will be removed.
In all of these examples, we've specified the mailbox identity and have been configuring the rules of a single mailbox. If you do not provide a value for the -Mailbox
parameter, the *-InboxRule
cmdlets will execute against the mailbox belonging to the user that is running the command.
There's more...
Now let's take a look at a practical example of how you might create inbox rules in bulk. The following code will create an inbox rule for every mailbox in the Sales OU:
$sales = Get-Mailbox -OrganizationalUnit contoso.com/sales $sales | %{ New-InboxRule -Name Junk ` -Mailbox $_.alias ` -SubjectContainsWords "[Spam]" ` -MoveToFolder "$($_.alias):\Junk E-Mail" }
What we are doing here is using the -SubjectContainsWords
parameter to check for a subject line that starts with "[Spam]". If there is a match, we move the message to the Junk E-Mail folder within that user's mailbox. As you can see, we are looping through each mailbox using the ForEach-Object
cmdlet (using the %
alias) and, within the loop, we specify the identity of the user when creating the inbox rule and when specifying the folder id, using the $_.alias
property.
Even if you are logged in using an account in the Organization Management group, you may receive errors when trying to use the –MoveToFolder
parameter when creating an inbox rule in another user's mailbox. Assigning FullAccess
permissions to the mailbox in question should resolve this issue. For more details, see Granting administrators full access to mailboxes in Chapter 10, Exchange Security.
See also
- Granting users full access permissions to mailboxes in Chapter 10, Exchange Security