Knowledge Base

How to get a list of email aliases from Microsoft 365

Problem:

You want to obtain a list of all email aliases configured in your Microsoft 365 organization. 

Aliases are alternative email addresses set for a mailbox. They can be used either to route emails to that mailbox or as an alternative From address. You can use aliases in CodeTwo Email Signatures 365 to apply alternative signatures to emails sent to alias addresses. Learn more

Solution:

While you can check this information manually in the Microsoft 365 admin center, doing so requires navigating to user profile cards one by one, which is not time-efficient. The easiest way to get a list of aliases in your Microsoft 365 tenant is by using PowerShell (see this article to learn more about connecting to your organization with PowerShell).

The script below returns a list of mailboxes with aliases configured. Check the comments in the script for more information.

Connect-ExchangeOnline # First, you need to connect Exchange Online with PowerShell. You’ll need to sign in with a Microsoft 365 admin account.

$mailboxes = (Get-Mailbox | select-object displayname, primarysmtpaddress, emailaddresses) # Gets relevant parameters of all mailboxes in your Microsoft 365 tenant. You can use -Filter to limit the number of processed mailboxes.

$AllAliases = @() # An array that will store users addresses and aliases.

foreach ($mailbox in $mailboxes){ #This script goes through the list of your mailboxes.

foreach ($address in $mailbox.EmailAddresses){

if ($address -match "smtp:"){ # Filters only SMTP addresses, leaves out, for example, SPO addresses.

$alias = New-Object PSObject # A new object that lists display names, primary SMTP address and aliases of mailboxes in your tenant.

$alias | add-member -type NoteProperty -name 'DisplayName' -Value $mailbox.DisplayName

$alias | add-member -type NoteProperty -name 'PrimarySmtpAddress' -Value $mailbox.PrimarySmtpAddress

$alias | add-member -type NoteProperty -name 'EmailAddress' -Value $address.Split(':')[1] # Gets only the email address, without its SMTP label.

if($alias.EmailAddress -ne $alias.PrimarySMTPAddress){ # Filters results so that only aliases are added to the $AllAliases array.

$AllAliases += $alias

}

}

}

}

$AllAliases # Shows the list of all mailboxes that have aliases configured. You can group results by adding | Group-Object DisplayName

Once you run the script, you'll get results similar to those shown in Fig. 1. Aliases are listed in the EmailAddress column.

Example of obtaining a list of aliases by using PowerShell.
Fig. 1. Example of obtaining a list of aliases by using PowerShell.

You can use the follow-up script below to list all aliases, separated by semicolons (as shown in Fig. 2.):

$AllAliases | foreach{

Write-Host $_.EmailAddress "; " -NoNewLine

}

All email aliases listed and separated by semicolons.
Fig. 2. All email aliases listed and separated by semicolons.

You can copy the results to your clipboard and paste them directly into CodeTwo Email Signatures 365 (Fig. 3.). For step-by-step instructions on how to set up different signatures for emails sent from alias addresses, see this article.

Creating a signature rule for email aliases in CodeTwo.
Fig. 3. Creating a signature rule for email aliases in CodeTwo.

Was this information useful?