List Mailbox Rules in Exchange Online

This post is meant to show a script list rules for a persons mailbox in Exchange Online. Of course this script is making use of Modern Authentication

# Install required modules if not already installed
if (!(Get-Module -Name ExchangeOnlineManagement -ErrorAction SilentlyContinue)) {
    Install-Module -Name ExchangeOnlineManagement -Force -AllowClobber
}
if (!(Get-Module -Name MSOnline -ErrorAction SilentlyContinue)) {
    Install-Module -Name MSOnline -Force -AllowClobber
}

# Connect to Exchange Online using modern authentication
$UserCredential = Get-Credential
Connect-ExchangeOnline -Credential $UserCredential

# Specify the user's email address
$EmailAddress = "user@example.com"

# Get the mailbox rules for the specified user
$MailboxRules = Get-InboxRule -Mailbox $EmailAddress

# Display the rules
if ($MailboxRules) {
    Write-Host "Rules applied to mailbox: $EmailAddress"
    Write-Host "-------------------------------------"

    $RuleCount = $MailboxRules.Count
    Write-Host "Total rules: $RuleCount"
    Write-Host

    $Index = 1
    foreach ($Rule in $MailboxRules) {
        Write-Host "Rule $Index:"
        Write-Host "   Name: $($Rule.Name)"
        Write-Host "   Enabled: $($Rule.Enabled)"
        Write-Host "   Description: $($Rule.Description)"
        Write-Host

        $Index++
    }
}
else {
    Write-Host "No rules found for mailbox: $EmailAddress"
}

# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false

Leave a Reply

Your email address will not be published. Required fields are marked *