skip to Main Content

List all SMTP addresses with PowerShell

Sometimes you want to list all SMTP addresses in Exchange Server. You need that list to gather information because you want to bulk remove secondary SMTP addresses from the mailboxes. The SMTP with an upper case is the primary email address, and the smtp with a lower case 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

Log into Exchange Admin Center and go to the properties of a mailbox. Click email address on the menu. 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

Start Active Directory Users and Computers, after that enable Advanced Features. Go to the user object properties and click on the attribute editor tab. Find the attribute proxyAddresses. The same two SMTP email addresses are shown as values, just like 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. Run the 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

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 lower case letters because it’s not the primary SMTP. The Primary SMTP is written in upper case 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

Export the results to CSV file

Export the results to a CSV file in the path C:\temp. Open the file with Microsoft Excel or any other application that you are are using.

[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

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

List all SMTP addresses with PowerShell CSV file

That’s 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

In this article, you learned how to list all SMTP addresses in Exchange Server with PowerShell. As shown in the article, run the cmdlet 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 Complete mailbox migration with bad items. 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 2 Comments

  1. Hi,

    The “Export the results to CSV file” powershell command is out of date:
    PS C:\Users\Kevin> [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
    At line:1 char:6
    + [PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayNam …
    + ~~~~~~~~~~~~~~~
    Unexpected token ‘C:\>Get-Mailbox’ in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

    1. Hi Kevin,

      The command is not out of date, and it works perfectly. It works for both Exchange on-premises and Exchange Online (Get-EXOMailbox cmdlet).

      You get this error because you copied the command including “[PS] C:\>”. Try again, but this time copy only the command WITHOUT “[PS] C:\>”.

Leave a Reply

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