Is there a way to see what mailboxes are being forwarded to a specific email address?

thecomputerguy

Well-Known Member
Reaction score
1,419
I feel like I'm asking for a powershell thing here.

Client is complaining about receiving too much garbage. After people are terminated depending on the position she wants emails forwarded to her. Over months/years she probably have 5-10 email accounts being forwarded to her.

Is there somewhere I can look or some powershell command I can run to see what mailboxes are being forwarded to her?
 
Is there somewhere I can look or some powershell command I can run to see what mailboxes are being forwarded to her?

Not discounting your question, as I'd be curious, too, doesn't this person know what accounts are being forwarded to her? That information should be pretty plain in the forwarded material. If there are ten or fewer accounts, you'd think she'd know "off the top of her head" where the stuff she doesn't want (that's also not garden variety spam) is coming from.
 
Yup Powershell can do that. Unfortunately, to the best of my knowledge, EAC GUI can only show individual mailbox properties including forwarding. For a small client...not a biggie. For a larger one...eh...whip out the powershell to list all.
After all of the powershell "connection" prompts...
Get-Mailbox | Select-Object DisplayName, ForwardingAddress, DeliverToMailboxAndForward
 
After people are terminated depending on the position she wants emails forwarded to her. Over months/years she probably have 5-10 email accounts being forwarded to her.
I think I learned this here, but when someone leaves I convert their mailbox to a shared mailbox and remove the license. Then give them access to the shared mailbox.
 
PowerShell! Copilot is your very best friend.

And yes, this... requires it. The GUI just can't do this as far as I know.

Copilot Prompt
Code:
please help me create a powershell script that can query M365 Exchange Online, and generate a list of email boxes that have email forwarding configured to target a specific mailbox.

Code:
# Define the target forwarding address
$TargetForwardingAddress = "target@example.com"

# Connect to Exchange Online (Ensure Exchange Online module is installed)
Connect-ExchangeOnline -UserPrincipalName admin@example.com

# Retrieve all mailboxes with forwarding enabled
$MailboxesWithForwarding = Get-Mailbox | Where-Object { $_.ForwardingSMTPAddress -ne $null }

# Filter mailboxes that forward to the specific address
$FilteredMailboxes = $MailboxesWithForwarding | Where-Object { $_.ForwardingSMTPAddress -eq $TargetForwardingAddress }

# Display results
$FilteredMailboxes | Select-Object DisplayName, PrimarySMTPAddress, ForwardingSMTPAddress | Format-Table -AutoSize

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

Of this code, I focus on the 2nd command... Because it's the bit that gets me a list of all email boxes that have forwarding enabled. This seems to be a good report to have in the stack of snips, so I'm changing gears to generate a full forwarding report I can open an massage in Excel!

Get-Mailbox | Where-Object { $_.ForwardingSMTPAddress -ne $null }

Back to Copilot, Prompt:

Code:
given this command: Get-Mailbox  Where-Object { $_.ForwardingSMTPAddress -ne $null }


How do I extend this output to list the UPN as well as the forwarding address?

Answer:
Code:
Get-Mailbox | Where-Object { $_.ForwardingSMTPAddress -ne $null } | Select-Object DisplayName, UserPrincipalName, ForwardingSMTPAddress | Format-Table -AutoSize

A quick execution against my own tenant returns a nice table of all users with forwards and targets! Perfection! Copilot inferred that DisplayName would be useful as well, and added that for me, unprompted!

One more quick tweak... This bit I do myself because I've done this 1000 times... I swear I live in Excel these days!

Code:
Get-Mailbox | Where-Object { $_.ForwardingSMTPAddress -ne $null } | Select-Object DisplayName, UserPrincipalName, ForwardingSMTPAddress | Export-Csv -Path "C:\Temp\MailboxForwardingReport.csv" -NoTypeInformation

And now I have a PowerShell snippet that can generate CSV exports of any tenant's forwarding configuration, open it up in Excel, format as a table and filter to find whatever specifics I want.

Please note, this action was completed via the free Copilot available as an app on any Windows 11 machine, as well as what's available for free at https://copilot.microsoft.com

$0 was spent to have AI assist me in creating this report, total time investment. ~5min.

I'm not personally capable of writing PowerShell myself, but I can read most programming languages and understand them. For those that do not know powershell, please remember that Get- commands are READ commands, they are safe to execute. If it doesn't work as expected, the risk of damage is virtually nonexistent! Experiment!

Now, when you start mucking about with the set- commands... there... be the dragons! Keep it short, keep it simple, take a moment to read and understand. And most importantly, never stop learning!
 
Last edited:
Back
Top