skip to Main Content

Find specific SMTP address with PowerShell

How to find a specific SMTP address with PowerShell in the Exchange Organization? You want to know how many mailboxes are configured with a specific SMTP address. In this article, you will learn how to search and list mailboxes in Exchange Server with a specific SMTP address.

Do you want to list all SMTP addresses in the Exchange Organization? Read how to list all SMTP addresses with PowerShell »

Find specific SMTP address with PowerShell

We like to find mailboxes with a specific SMTP address in Exchange Server. These are the primary SMTP address and the secondary SMTP address, also known as alias address.

Run Exchange Management Shell as administrator. Run the cmdlet to list the mailboxes with that particular domain.

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -Like "*@alitajran.com"} | Sort-Object Name

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                alitajran            ex01-2016        Unlimited
Benetiz Anees             Benetiz.Anees        ex01-2016        Unlimited
Boris Campbell            boris.campbell       ex01-2016        Unlimited
Carl Kelly                carl.kelly           ex01-2016        Unlimited
Christopher Payne         christopher.payne    ex01-2016        Unlimited

Tweak the table view and add the information you need to the Select-Object cmdlet. For example, DisplayName, PrimarySMTPAddress, and EmailAddresses.

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -Like "*@alitajran.com"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses | Where-Object {$_ -clike "smtp*"}}} | Select-Object DisplayName, PrimarySMTPAddress, EmailAddresses | Sort-Object DisplayName

DisplayName       PrimarySmtpAddress          EmailAddresses
-----------       ------------------          --------------
Administrator     Administrator@exoip.com     {smtp:Administrator@alitajran.com, smtp:Administrator@exoip.local}
Ali Tajran        Ali.Tajran@exoip.com        smtp:alitajran@alitajran.com
Benetiz Anees     Benetiz.Anees@exoip.com     smtp:Benetiz.Anees@alitajran.com
Boris Campbell    Boris.Campbell@exoip.com    {smtp:Boris.Campbell@contoso.com, smtp:Boris.Campbell@alitajran.com}
Carl Kelly        Carl.Kelly@exoip.com        smtp:carl.kelly@alitajran.com
Christopher Payne Christopher.Payne@exoip.com smtp:christopher.payne@alitajran.com

For a cleaner look, remove smtp: from the secondary SMTP addresses.

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -Like "*@alitajran.com"} | 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@alitajran.com, Administrator@exoip.local
Ali Tajran        Ali.Tajran@exoip.com        alitajran@alitajran.com
Benetiz Anees     Benetiz.Anees@exoip.com     Benetiz.Anees@alitajran.com
Boris Campbell    Boris.Campbell@exoip.com    Boris.Campbell@contoso.com, Boris.Campbell@alitajran.com
Carl Kelly        Carl.Kelly@exoip.com        carl.kelly@alitajran.com
Christopher Payne Christopher.Payne@exoip.com christopher.payne@alitajran.com

Export to CSV file

We like to export the mailboxes with a specific SMTP address to CSV. This will export the CSV file to C:\temp\. Don’t forget to create a temp folder on the C drive or edit the export path.

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

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

Find specific SMTP address with PowerShell CSV file

I hope it helped you to search and list the mailboxes that have a specific SMTP address configured.

Keep reading: How to bulk remove secondary SMTP address with PowerShell »

Conclusion

In this article, you learned how to find a specific SMTP address with PowerShell in Exchange Server. Run the cmdlet in PowerShell to get a list of the mailboxes with a specific SMTP address. Adjust the Select-Object cmdlet with the values you want to see. After that, export the list to CSV file and open it with your favorite CSV viewer/editor.

Did you enjoy this article? You may also like Bulk create AD Users with random passwords. 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. Your script doesn’t return the EmailAddresses but only the PrimarySmtpAddress. I’m trying to export list of migrated users from our environment, which are having a secondary email address from their previous tenant. Users seems to be identified correctly, but all the secondary email addresses are not listed in the export.

    1. As you can see from the imported CSV file in Microsoft Excel, it did work correctly. Unfortunately, it’s not working on your end. It’s difficult for me to give you an answer or tweak the cmdlet to your needs without reproducing the issue.

Leave a Reply

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