Retrieve Inbox Rules in Office 365 Exchange Online

Introduction

This script demonstrates how to get inbox rules in Office 365 Exchange Online. You can get inbox rules for multiple rules with this script.

Scenario

Currently, you can easily create inbox rules in Outlook Web App (OWA). But after creating multiple inbox rules, you find it is difficult for troubleshooting if something goes wrong. So you want to find a script to document the details of a rule.

Prerequisite

This script requires Exchange Web Service Managed API 2.0. Please download and install the package from Microsoft Download Center. This script cannot work correctly without this package.

Script

This script contains the following advanced functions:

You can use this script in the following way.

  1. Open Windows PowerShell.
  2. Run Import-Module cmdlet to import this module file.
    Import-Module filepath\scriptname.psm1

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
# Get Inbox Rules 
$inboxRules = $exService.GetInboxRules() 
  
if ($inboxRules.Count -eq 0{ 
    $warningMsg = $Messages.CannotFindInboxRule 
    if (-not [System.String]::IsNullOrEmpty($Identity)) { 
        $warningMsg = $warningMsg -f $userSMTPAddress 
    } else { 
        $warningMsg = $warningMsg -f $exService.Credentials.Credentials.UserName 
    } 
    $PSCmdlet.WriteWarning($warningMsg) 
} else { 
    # Clear ImpersonationID 
    $exService.ImpersonatedUserId = $null 
  
    # Return Inbox Rules 
    return $inboxRules         
}

Examples

Example 1: How to display help about Get-OSCEXOInboxRule.
To display help about this function, run this command.
Get-Help Get-OSCEXOInboxRule -Full

Example 2: How to initiate a connection to Office 365 Exchange Online.
To initiate a connection to Office 365 Exchange Online, please run this command. You must run this example before any other step.
Connect-OSCEXOWebService -Credential (Get-Credential admin@domain01.onmicrosoft.com)

Note The Connect-OSCEXOWebService function creates a new variable called exService. This variable is in the global scope of the current Windows PowerShell session. This variable is used by other functions in the script.

Example 3: How to retrieve inbox rules for the user who established the connection to Office 365 Exchange Online web service.
To retrieve inbox rules for the user who established the connection to Office 365 Exchange Online web service, please run this command.
Get-OSCEXOInboxRule

Example 4: How to retrieve inbox rules for John Doe (johnd) and expand Actions property.
To retrieve inbox rules for John Doe (johnd) and expand Actions property, please run this command.
Get-OSCEXOInboxRule -Identity johnd | Select -ExpandProperty Actions

Example 5: How to retrieve inbox rules for John Doe (johnd) and Jane Doe (janed).
To retrieve inbox rules for John Doe (johnd) and Jane Doe (janed), please run this command.
"johnd","janed" | Get-OSCEXOInboxRule

Additional Resources

Technical Resources:
Windows PowerShell Advanced Function
Getting Inbox rules by using the EWS Managed API

Forum Threads:
http://community.office365.com/en-us/forums/148/t/125702.aspx
http://community.office365.com/en-us/forums/148/t/147835.aspx