All scripts
Microsoft 365 309

Get-EmailAliasInventory

Exports every SMTP alias for every mailbox in the tenant, flagging any mailbox with an unusually high alias count, which is often a sign of leftover aliases from old naming conventions.

Get-EmailAliasInventory.ps1
<#
.SYNOPSIS
    Exports all SMTP aliases across the tenant.

.DESCRIPTION
    Reads the EmailAddresses property of every mailbox, extracts the
    secondary SMTP aliases, and flags mailboxes with more aliases than a
    configurable threshold, since a pile of unused aliases is usually
    leftover from an old naming convention or a migration nobody cleaned up.

.PARAMETER AliasWarningCount
    Number of secondary aliases considered worth flagging. Defaults to 3.

.EXAMPLE
    .\Get-EmailAliasInventory.ps1 -AliasWarningCount 5

.NOTES
    Requires ExchangeOnlineManagement and an active Connect-ExchangeOnline session.

.AUTHOR
    Shehryar Hassan
#>

param(
    [int]$AliasWarningCount = 3
)

$mailboxes = Get-Mailbox -ResultSize Unlimited
$report = foreach ($mbx in $mailboxes) {
    $aliases = $mbx.EmailAddresses | Where-Object { $_ -clike "smtp:*" }
    [pscustomobject]@{
        DisplayName = $mbx.DisplayName
        Primary     = $mbx.PrimarySmtpAddress
        AliasCount  = $aliases.Count
        Aliases     = ($aliases -replace "smtp:", "") -join "; "
        Flag        = $aliases.Count -ge $AliasWarningCount
    }
}

$report | Sort-Object AliasCount -Descending | Format-Table DisplayName, Primary, AliasCount, Flag -AutoSize

Read it before you run it, and test in a safe tenant first.