After you set up the Database Availability Group (DAG), you want to add a database…
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.
Table of contents
Find SMTP addresses in Exchange Admin Center
- Sign in to 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.
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, as we saw earlier in the Exchange Admin Center.
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.
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.
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
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?
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.
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.
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?
You can read the article: Find IP addresses using Exchange SMTP relay.
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…
Hi Chato,
This is what you want: Find specific SMTP address with PowerShell.