Skip to content

List all SMTP addresses with PowerShell

Sometimes you want to list all SMTP addresses in Exchange Server or Exchange Online. You need that list to gather information because you want to bulk remove secondary SMTP addresses from the mailboxes. The SMTP with an uppercase is the primary email address, and the smtp with a lowercase is the secondary email address, also known as the alias address. The email addresses are configured as proxy addresses in Active Directory. In this article, you will learn how to list all SMTP addresses with PowerShell.

Find SMTP addresses in Exchange Admin Center

  1. Sign in to Exchange Admin Center and go to the properties of a mailbox.
  2. Click email address on the menu.
  3. View the configured email addresses.

You can add, change, or delete an email address. There are two SMTP email addresses configured for the user.

List all SMTP addresses with PowerShell email address

Find SMTP addresses in Active Directory

  1. Start Active Directory Users and Computers. After that, enable Advanced Features.
  2. Go to the user object properties and click on the attribute editor tab.
  3. Find the attribute proxyAddresses.

The same two SMTP email addresses are shown as values, as we saw earlier in the Exchange Admin Center.

List all SMTP addresses with PowerShell ProxyAddresses

You have seen the SMTP addresses in both places. How to get a list of all the mailboxes, including their SMTP addresses? Read more about it in the next part.

List all primary SMTP addresses

Run Exchange Management Shell as administrator or connect to Exchange Online PowerShell.

Note: The below commands work for Exchange Server on-premises and Exchange Online.

Run the Get-Mailbox cmdlet to list the mailboxes with the primary SMTP address.

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress | Sort-Object DisplayName

DisplayName              PrimarySmtpAddress
-----------              ------------------
Administrator            Administrator@exoip.com
Ali Tajran               Ali.Tajran@exoip.com
Amanda Morgan            Amanda.Morgan@exoip.com
Anna Welch               Anna.Welch@exoip.com
Benetiz Anees            Benetiz.Anees@exoip.com
Boris Campbell           Boris.Campbell@exoip.com
Carl Kelly               Carl.Kelly@exoip.com
Christopher Payne        Christopher.Payne@exoip.com
Discovery Search Mailbox MsExchDiscoveryMailboxD919BA05-46A6-415f-80AD-7E09334BB852@exoip.com
Elizabeth Roberts        Elizabeth.Roberts@exoip.com
Emma Underwood           Emma.Underwood@exoip.com
Hannah Walker            Hannah.Walker@exoip.com
Jake Cornish             Jake.Cornish@exoip.com

Run the Get-Recipient cmdlet if you want to get all the objects in the organization. This will get the mailboxes, distribution groups, security groups, and contacts.

[PS] C:\>Get-Recipient -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress | Sort-Object DisplayName

In our Exchange organization, we have more than one email address for the same mailbox. In the next part, we will list these secondary email addresses.

List all SMTP email addresses

In the previous part, we listed the primary SMTP address of every mailbox in the Exchange organization. Now we like to have a list including the secondary SMTP addresses. How will we add this to the existing PowerShell cmdlet?

We are going to make use of the script block. A script block is a collection of statements or expressions that can be used as a single unit. By using that, it will gather all the SMTP email addresses. Note that the SMTP is written in lowercase letters because it’s not the primary SMTP. The Primary SMTP is written in uppercase letters.

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName

DisplayName              PrimarySmtpAddress                                                   EmailAddresses
-----------              ------------------                                                   --------------
Administrator            Administrator@exoip.com                                              Administrator@exoip.local
Ali Tajran               Ali.Tajran@exoip.com
Amanda Morgan            Amanda.Morgan@exoip.com                                              Amanda.Morgan@alitajran.com
Anna Welch               Anna.Welch@exoip.com
Benetiz Anees            Benetiz.Anees@exoip.com
Boris Campbell           Boris.Campbell@exoip.com                                             Boris.Campbell@contoso.com, Boris.Campbell@alitajran.com
Carl Kelly               Carl.Kelly@exoip.com
Christopher Payne        Christopher.Payne@exoip.com
Discovery Search Mailbox MsExchDiscoveryMailboxD919BA05-46A6-415f-80AD-7E09334BB852@exoip.com DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852}@exoip.local
Elizabeth Roberts        Elizabeth.Roberts@exoip.com
Emma Underwood           Emma.Underwood@exoip.com
Hannah Walker            Hannah.Walker@exoip.com
Jake Cornish             Jake.Cornish@exoip.com

Run the Get-Recipient cmdlet if you want to get all the objects in the organization. This will get the mailboxes, distribution groups, security groups, and contacts.

[PS] C:\>Get-Recipient -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName

Add the OutGrid-View cmdlet at the end of the command to output the information to a grid view window.

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName | Out-GridView
[PS] C:\>Get-Recipient -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName | Out-GridView

Export the results to CSV file

Export the results to a CSV file in the path C:\temp.

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName | Export-CSV "C:\temp\List_SMTP_Addresses.csv" -NoTypeInformation -Encoding UTF8
[PS] C:\>Get-Recipient -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName | Export-CSV "C:\temp\List_SMTP_Addresses.csv" -NoTypeInformation -Encoding UTF8

Open the exported CSV file with Microsoft Excel or any other CSV file editor/viewer.

List all SMTP addresses with PowerShell CSV file

Everything looks great! I hope that it helped you to export all email addresses to a CSV file.

Read more: Export mailbox folder permissions to CSV file »

Conclusion

You learned how to list all SMTP addresses in Exchange Server and Exchange Online with PowerShell. Run the commands to get a list of the mailboxes with SMTP addresses. Export the list to CSV and go through it with Microsoft Excel.

Did you enjoy this article? You may also like Find missing SMTP address with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 10 Comments

  1. A really great article that really helped me. 🙂

    I have one question: What if I only want to display the users for whom “EmailAddresses” is NOT empty?

    Best regards,
    Kortschnoi

  2. Thank you so much! This really helps us to find the “forgotten” mail addresses! The migration to Office365 is much easier now! Especially the export to CSV is great!!

    Regards,

    Mick

  3. Hi, thanks for sharing.

    Once we have the list of all email addresses, can that output be used to import to a new M365 tenant (thinking for a divestiture scenario). Is that format valid for import or does it need manipulated?

  4. I get only partial results, we have users that have multiple aliases and the result contain only three email addresses, I’ve been trying to get ALL email addresses and still cannot do it.

    1. I tested the commands in Exchange on-premises and Exchange Online. It works fine over here with multiple aliases.

      The PowerShell output might not show all the results. You should export the results to a CSV file and open the CSV file with your favorite program.

  5. This is awesome! Thank you so much for doing this excellent article. Do you have a Powershell command that would identify what application that are using SMTP for authentication in Active Directory?

  6. Hi Ali. Great post!
    If to filter for a spesific domain suffix in array of proxyaddresses, could I amend Where-Object {$_ -clike “smtp*”} to i.e. Where-Object {$_ -like “*contoso.com”}?
    I don’t have any luck doing this so obviously I’m doing something wrong…

Leave a Reply

Your email address will not be published. Required fields are marked *