added ExchangeOnline directory and tenant mailbox rule export script

This commit is contained in:
Kyle 2025-10-22 10:04:16 +08:00
parent a7fcad8708
commit b3218f82a3

View File

@ -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
}
}