How to Retrieve All SMTP (Email) Addresses Using PowerShell in Exchange

Occasionally, it may be necessary to export a complete list of email addresses in your Exchange organization. This article will guide you on how to obtain and export all assigned SMTP addresses to a CSV file in Exchange Server or Microsoft 365 (Exchange Online) using PowerShell.

Here’s how to connect to your Exchange organization:

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.

The proxyAddresses attribute is used to set the email delivery address in the on-premises Active Directory.

A user is assigned multiple additional SMTP addresses, which are preserved in the EmailAddresses string attribute. Other forms of addresses might also exist within this attribute; hence, to obtain a compilation of all the SMTP addresses of a mailbox, execute 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 showcases all primary addresses and aliases for every user mailbox 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:PSList-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 Azure). 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

If you need to find Exchange objects with the same (duplicate) recipient SMTP address, run:

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:", "") }

Unique SMTP addresses were also generated for the Microsoft Teams channel.

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


Posted

in

, ,

by

Tags: