How to generate a list in exchange, user have set a rules in Auto Forwarding emails to Another Mailbox using powershell

JYLVEN TARRAJA 80 Reputation points
2025-01-28T05:39:48.2333333+00:00

Please help me to generate a report via in a powershell, to view the list of mailbox name, Inbox rule, Forward to, Redirect to Forward as Attachment and rule status.

Thank you

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
Exchange Exchange Server Development
Exchange Exchange Server Management
Windows for business Windows Server User experience PowerShell
{count} votes

2 answers

Sort by: Most helpful
  1. Kavya 490 Reputation points
    2025-01-30T08:09:15.62+00:00

    You can run the below script after connecting to Exchange Online PowerShell.

    Get-Mailbox -ResultSize unlimited | foreach { Get-InboxRule -Mailbox $_.DisplayName | select mailboxownerid,redirectTo,ForwardTo,ForwardAsAttachmentTo }
    

    To connect to Exchange Online PowerShell, run the below cmdlet.
    Connect-ExchangeOnline

    If you need to export the report to a CSV file, you can download the script from GitHub. Since some properties include values with additional formats, extra handling is required for proper CSV export.
    https://github.com/admindroid-community/powershell-scripts/blob/master/Office%20365%20Email%20Forwarding%20Report/EmailForwardingReport.ps1

    0 comments No comments

  2. Anonymous
    2025-01-31T07:06:45.07+00:00

    Hi @JYLVEN TARRAJA ,

    Here is a PowerShell script that you can use to generate a report of mailbox names, inbox rules, forwarding addresses, and rule status in Exchange Online:

    # Connect to Exchange Online
    $UserCredential = Get-Credential
    Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName -Password $UserCredential.GetNetworkCredential().Password
    # Get all mailboxes
    $mailboxes = Get-Mailbox -ResultSize Unlimited
    # Initialize an array to store report data
    $report = @()
    foreach ($mailbox in $mailboxes) {
    # Get the inbox rules for each mailbox
    $rules = Get-InboxRule -Mailbox $mailbox.PrimarySmtpAddress
    foreach ($rule in $rules) {
    # Create a custom object for each rule
    $ruleDetails = [PSCustomObject]@{
    MailboxName = $mailbox.DisplayName
    RuleName = $rule.Name
    ForwardTo = ($rule.ForwardTo | ForEach-Object { $_.PrimarySmtpAddress }) -join ", "
    RedirectTo = ($rule.RedirectTo | ForEach-Object { $_.PrimarySmtpAddress }) -join ", "
    ForwardAsAttachmentTo = ($rule.ForwardAsAttachmentTo | ForEach-Object { $_.PrimarySmtpAddress }) -join ", "
    RuleStatus = $rule.Enabled
    }
    # Add rule details to report array
    $report += $ruleDetails
    }
    }
    # Export report to CSV file
    $report | Export-Csv -Path "C:\InboxRulesReport.csv" -NoTypeInformation
    # Disconnect from Exchange Online
    Disconnect-ExchangeOnline -Confirm:$false
    

    This script will:

    1. Connect to Exchange Online.
    2. Retrieve all mailboxes.
    3. For each mailbox, get the Inbox rules and their details.
    4. Create a custom object for each rule that contains the required information.
    5. Export the report to a CSV file named InboxRulesReport.csv.

    Make sure you run this script in a PowerShell session that has the necessary permissions and the Exchange Online module installed.


    Please feel free to contact me for any updates. And if this helps, don't forget to mark it as an answer.

    Best,

    Jake Zhang


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.