Mailbox forwarding is a sensitive configuration in Microsoft 365. While it’s sometimes enabled for legitimate business workflows, it’s also a common indicator of data leakage risk and account compromise. A tenant can silently accumulate forwarding-enabled mailboxes over time, and without periodic review, administrators may not know which accounts are forwarding messages externally or to other internal recipients.
One challenge is that Microsoft Graph does not expose mailbox forwarding properties through mailboxSettings, which means you can’t reliably audit forwarding using Graph cmdlets alone. However, Exchange Online PowerShell does surface forwarding settings, and once the report is generated, it can still be emailed without SMTP using Graph Send-MgUserMail.
This script combines both tools:
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
$SenderUPN = "admin@yourtenant.onmicrosoft.com"
$Recipients = @(
"admin@yourtenant.onmicrosoft.com",
"securityteam@yourtenant.onmicrosoft.com"
)
Connect-ExchangeOnline
Connect-MgGraph -Scopes "Mail.Send","User.Read.All"
$Mailboxes = Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox `
-Properties ForwardingSmtpAddress,ForwardingAddress,DeliverToMailboxAndForward
$Report = @()
foreach ($mbx in $Mailboxes) {
if ($mbx.ForwardingSmtpAddress -or $mbx.ForwardingAddress) {
$ForwardTo = if ($mbx.ForwardingSmtpAddress) {
$mbx.ForwardingSmtpAddress
} else {
$mbx.ForwardingAddress
}
$Report += [PSCustomObject]@{
"User Name" = $mbx.DisplayName
"User Principal Name" = $mbx.UserPrincipalName
"Mailbox" = $mbx.PrimarySmtpAddress
"Forwarding Destination" = $ForwardTo
"DeliverToMailboxAndForward" = $mbx.DeliverToMailboxAndForward
}
}
}
$ReportPath = "$env:TEMP\Mailbox_Forwarding_Enabled_Users.csv"
if ($Report.Count -gt 0) {
$Report | Sort-Object "User Name" |
Export-Csv -Path $ReportPath -NoTypeInformation -Encoding utf8
} else {
"No licensed users with mailbox forwarding enabled were found." |
Set-Content -Path $ReportPath -Encoding utf8
}
$Bytes = [System.IO.File]::ReadAllBytes($ReportPath)
$Utf8Bom = New-Object System.Text.UTF8Encoding($true)
[System.IO.File]::WriteAllText($ReportPath, [System.Text.Encoding]::UTF8.GetString($Bytes), $Utf8Bom)
$Count = $Report.Count
$Subject = "Mailbox Forwarding Enabled Users — $(Get-Date -Format 'yyyy-MM-dd')"
$Body = @"
Hello Team,<br><br>
Attached is the <b>Mailbox Forwarding Enabled Users</b> report.<br>
This report is generated from Exchange Online mailbox properties and mailed via Microsoft Graph.<br><br>
Total forwarding-enabled users found: <b>$Count</b><br><br>
Regards,<br>
PowerShell Automation
"@
$AttachmentContent = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes($ReportPath))
$Attachments = @(
@{
"@odata.type" = "#microsoft.graph.fileAttachment"
Name = "Mailbox_Forwarding_Enabled_Users.csv"
ContentBytes = $AttachmentContent
}
)
$ToRecipients = $Recipients | ForEach-Object {
@{ EmailAddress = @{ Address = $_ } }
}
$Message = @{
Message = @{
Subject = $Subject
Body = @{
ContentType = "HTML"
Content = $Body
}
ToRecipients = $ToRecipients
Attachments = $Attachments
}
SaveToSentItems = "true"
}
Send-MgUserMail -UserId $SenderUPN -BodyParameter $Message
Write-Host "Mailbox forwarding report emailed successfully (EXO + Graph)." -ForegroundColor Green
You provide:
| Error | Cause | Solution |
|---|---|---|
| Connect-ExchangeOnline fails | Exchange Online module not installed or outdated. | Install/update and reconnect Exchange Online module. |
| Empty report | No mailboxes currently have forwarding enabled. | Valid outcome — script still sends a readable CSV. |
| Graph email send fails | Missing Mail.Send permission or no admin consent. | Grant consent and reconnect with: Connect-MgGraph -Scopes "Mail.Send","User.Read.All" |
| Sender mailbox not found | Sender UPN is not mailbox-enabled or lacks license. | Use a licensed mailbox (admin/shared mailbox). |
Mailbox forwarding is a high-value security signal in Microsoft 365, but Graph alone can’t audit it because forwarding properties aren’t exposed through Graph mailbox settings. Exchange Online PowerShell provides the accurate forwarding data, while Graph PowerShell gives a modern SMTP-less way to distribute reports automatically.
This hybrid scripting approach ensures:
Run this regularly to keep forwarding governance transparent and audit-ready.
© m365corner.com. All Rights Reserved. Design by HTML Codex