Skip to 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.

Find specific SMTP address with PowerShell

You can sign in to Exchange Admin Center (EAC), open the mailboxes one for one, and find the specific SMTP address. However, I don’t recommend doing that unless you have a lot of time and like to spend it that way.

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

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

Connect with the Exchange management tools before you run the commands:

Note: Change the Get-Mailbox to Get-Recipient in the commands to display all the objects in the organization. This will get the mailboxes, distribution groups, security groups, and contacts.

Find specific SMTP address by domain

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

Find specific SMTP address by name

Maybe you want to search for a name instead of a domain. What do you need to change to make that possible? Change the domain *@alitajran.com to a name that contains the SMTP address. For example, *tajran*. This will search for everything with that name in all the SMTP fields.

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*tajran*"} | 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

List informative result

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

Adust output for cleaner view

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

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 3 Comments

  1. If i want to fetch email address of the user with UPN, is there a Way
    Ex: i have a list of 2k users with UPN, i need email address of those users

    1. Change the property in the filter parameter from “EmailAddresses” to “UserPrincipalName”.

      It will look like this:

      Get-Mailbox -ResultSize Unlimited -Filter {UserPrincipalName -like "*@alitajran.com"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName

Leave a Reply

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