Skip to content

Find missing SMTP address with PowerShell

The users with a mailbox in Exchange Server need to have a specific SMTP address configured. How to search for the mailboxes with the missing SMTP address in Exchange? The answer is with PowerShell. If we find the missing SMTP address, we can add it to the user mailbox. In this article, you will learn how to find missing SMTP address with PowerShell.

Find missing SMTP address with PowerShell

You can sign in to Exchange Admin Center (EAC), open the mailboxes one for one, and find the missing 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 missing SMTP address by domain

Run the Get-Mailbox cmdlet to list the mailboxes with the missing domain. Good to know is that it will search both the primary SMTP address and secondary SMTP address in each mailbox for the missing SMTP address.

Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -notlike "*@alitajran.com"} | Sort-Object Name

The output below appears.

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Amanda Morgan             amanda.morgan        ex01-2016        Unlimited
Anna Welch                anna.welch           ex01-2016        Unlimited

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

Get-Recipient -ResultSize Unlimited -Filter {EmailAddresses -notlike "*@alitajran.com"} | Sort-Object Name

The below output appears.

Name          RecipientType
----          -------------
Alison Bell   MailUser
All Staff     MailUniversalDistributionGroup
Amanda Morgan UserMailbox
Anna Welch    UserMailbox

Find missing SMTP address by name

Maybe you want to search for a name instead of a domain.

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.

Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -notlike "*tajran*"} | Sort-Object Name
Get-Recipient -ResultSize Unlimited -Filter {EmailAddresses -notlike "*tajran*"} | Sort-Object Name

List informative result

Add the information you need to the Select-Object cmdlet. This will give you a better view of the mailboxes missing the SMTP address.

Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -notlike "*@alitajran.com"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses | Where-Object {$_ -clike "smtp*"}}} | Select-Object DisplayName, PrimarySMTPAddress, EmailAddresses | Sort-Object DisplayName
Get-Recipient -ResultSize Unlimited -Filter {EmailAddresses -notlike "*@alitajran.com"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses | Where-Object {$_ -clike "smtp*"}}} | Select-Object DisplayName, PrimarySMTPAddress, EmailAddresses | Sort-Object DisplayName

The below output appears.

DisplayName   PrimarySmtpAddress      EmailAddresses
-----------   ------------------      --------------
Amanda Morgan Amanda.Morgan@exoip.com smtp:A.Morgan@exoip.com
Anna Welch    Anna.Welch@exoip.com

Adjust output for a cleaner view

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

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

The output looks better.

DisplayName   PrimarySmtpAddress      EmailAddresses
-----------   ------------------      --------------
Amanda Morgan Amanda.Morgan@exoip.com A.Morgan@exoip.com
Anna Welch    Anna.Welch@exoip.com

The last step is to export the results to CSV file.

Read more: How to bulk remove secondary SMTP address with PowerShell »

Export to CSV file

Export the mailboxes with missing SMTP addresses to a CSV file. 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.

Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -notlike "*@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\Missing_SMTP_Addresses.csv" -NoTypeInformation -Encoding UTF8
Get-Recipient -ResultSize Unlimited -Filter {EmailAddresses -notlike "*@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\Missing_SMTP_Addresses.csv" -NoTypeInformation -Encoding UTF8

Go to the path in File Explorer and open the CSV file with your favorite application. For example, with Microsoft Excel.

Find missing SMTP address with PowerShell CSV file.png

That’s it!

What if you want to find a specific SMTP address instead of a missing SMTP address? Read more: Find specific SMTP address with PowerShell »

Conclusion

You learned how to find a missing SMTP address in Exchange Server or Exchange Online with PowerShell. Run the cmdlet in PowerShell to get a list of the mailboxes with missing 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 Export a list of mailboxes to CSV in Exchange. 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 0 Comments

Leave a Reply

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