Script To Get A List Of All Mailboxes Along with All its Email Aliases

Connect to Exchange Online

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://outlook.office365.com/powershell-liveid/ -Authentication Basic -AllowRedirection:$true -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking:$true -AllowClobber:$true | Out-Null

Get all Exchange Online users

$AllUsers = Get-Mailbox -ResultSize Unlimited

Iterate through each user and retrieve email address aliases

foreach ($User in $AllUsers) {
$UserPrincipalName = $User.UserPrincipalName
$PrimarySMTP = $User.PrimarySmtpAddress
$EmailAliases = $User.EmailAddresses

# Output the information
Write-Host "User: $UserPrincipalName"
Write-Host "Primary SMTP: $PrimarySMTP"
Write-Host "Email Aliases: $($EmailAliases -join ', ')"
Write-Host "----------------------------------------"

}

Disconnect from the Exchange Online session

Remove-PSSession $Session

Please note:

  1. This script requires you to enter your credentials when prompted. Ensure that the account has the necessary permissions to access Exchange Online. You can use Global Admin account.
  2. Make sure you have the Exchange Online PowerShell module installed. You can install it by following the instructions here: Connect to Exchange Online PowerShell.
  3. The script uses the Get-Mailbox cmdlet to retrieve all Exchange Online users. Adjust the parameters as needed based on your requirements.
  4. The script outputs the user’s principal name, primary SMTP address, and a list of email aliases.

Remember to test scripts in a controlled environment before using them in a production environment.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑