From b3218f82a33634ad3b40c08dcc2379bdbba6676a Mon Sep 17 00:00:00 2001 From: Kyle Pope Date: Wed, 22 Oct 2025 10:04:16 +0800 Subject: [PATCH] added ExchangeOnline directory and tenant mailbox rule export script --- .../Export-AllUserMailboxRules.ps1 | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Cloud/Microsoft365/ExchangeOnline/Export-AllUserMailboxRules.ps1 diff --git a/Cloud/Microsoft365/ExchangeOnline/Export-AllUserMailboxRules.ps1 b/Cloud/Microsoft365/ExchangeOnline/Export-AllUserMailboxRules.ps1 new file mode 100644 index 0000000..ff372c8 --- /dev/null +++ b/Cloud/Microsoft365/ExchangeOnline/Export-AllUserMailboxRules.ps1 @@ -0,0 +1,30 @@ +# Script will connect to ExchangeOnline, gather all user inbox rules across the tenant and export to a CSV file locally. +# Internal forwarding will appear as "Display Name" and include MailOwnerId in rule +# External forwarding will appear as "email@domain.com" [SMTP:email@domain.com] + +# Create export path +$exportPath = "C:\temp\exports\UserMailboxRulesExport.csv" + +# Prepare file (optional: overwrite each time script runs) +if (Test-Path $exportPath) { Remove-Item $exportPath } + +# Get all mailboxes +$users = Get-Mailbox -ResultSize Unlimited + +foreach ($user in $users) { + $rules = Get-InboxRule -Mailbox $user.UserPrincipalName | Select-Object ` + @{Name='DisplayName'; Expression={$user.DisplayName}}, + @{Name='EmailAddress'; Expression={$user.PrimarySmtpAddress}}, + MailboxOwnerID, + Name, + Description, + Enabled, + RedirectTo, + MoveToFolder, + ForwardTo + + # Export rules if any exist + if ($rules) { + $rules | Export-Csv $exportPath -NoTypeInformation -Append + } +}