From time to time, you may need to export the full list of email addresses in your Exchange organization. In this article we will show how to get and export all the assigned SMTP addresses to a CSV file in Exchange Server or Microsoft 365 (Exchange Online) using PowerShell.
Connect to your Exchange organization:
- You can use the Exchange Management Shell (EMS) module to manage on-premises Exchange Server, or you can connect to Exchange remotely from a regular PowerShell console;
- Use the Exchange Online PowerShell module (EXO) to connect Microsoft 365 tenant.You can use certificate-based authentication to sign in to Exchange Online from within PowerShell.
To view all primary and additional SMTP addresses for a specific Exchange mailbox, run this command:
Get-Mailbox testmax |Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses|fl
- The
SMTP
address in uppercase contains the primary email address - The lowercase
smtp
values are the secondary (alias) email addresses.
As you can see, a user is assigned several additional SMTP addresses, which are stored in the EmailAddresses string attribute. There may be other types of addresses in this attribute, so to get a list of all the SMTP addresses of a mailbox, run the command below:
Get-Mailbox testmax | Select-Object DisplayName,PrimarySmtpAddress, @{Name="SMTPAliases";Expression={($_.EmailAddresses | Where-Object { $_ -match "^smtp:" } | ForEach-Object {$_ -replace "smtp:",""}) -join "," }}
The following command displays all primary addresses and aliases for all user mailboxes and shared mailboxes in Exchange and exports the results to a CSV file:
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="SMTPAliases";Expression={($_.EmailAddresses | Where-Object { $_ -match "^smtp:" } | ForEach-Object {$_ -replace "smtp:",""}) -join "," }} | Export-Csv "C:\PS\List-All-SMTP-Addresses.csv" -NoTypeInformation -Encoding UTF8
The Get-Mailbox cmdlet displays only information about users and shared mailboxes.
In Active Directory (or Azure AD), there may be other types of objects with SMTP addresses assigned (mail-enabled objects): distribution groups, contacts, and Microsoft 365 groups (Unified Groups in Entra ID). Use the Get-Recipient cmdlet to list the SMTP addresses of all the objects in an Exchange organization/tenant:
Get-Recipient -ResultSize Unlimited | Select-Object DisplayName, RecipientType, PrimarySmtpAddress, @{Name="SMTPAliases";Expression={($_.EmailAddresses | Where-Object { $_ -match "^smtp:" } | ForEach-Object {$_ -replace "smtp:",""}) -join "," }}
In this case, we have a list of the SMTP addresses of all types of Exchange objects. To export only SMTP addresses of a specific object type, add the following parameter to the first cmdlet
Get-Recipient -ResultSize Unlimited -RecipientType your_object_type | …
Possible types of Exchange objects:
- DynamicDistributionGroup
- MailContact
- MailNonUniversalGroup
- MailUniversalDistributionGroup
- MailUniversalSecurityGroup
- MailUser
- PublicFolder
- UserMailbox
Get-Recipient -resultsize unlimited | where {$_.EmailAddresses -like "*[email protected]*"}
You can also get a flat list of SMTP addresses in Exchange:
Get-Recipient | Select-Object -ExpandProperty EmailAddresses | Where-Object { $_ -match "^smtp:" } | ForEach-Object { $_.Replace("smtp:", "").Replace("SMTP:", "") }
View the number of unique SMTP addresses in your Exchange organization:
Get-Recipient -ResultSize Unlimited | Select-Object -ExpandProperty EmailAddresses | Where-Object { $_ -match "^smtp:" }| measure-object