Find Email Addresses in Office 365 with PowerShell

Sometimes you need to find the user or a mailbox that is using a particular email address. Especially aliases are sometimes hard to find, and you don’t want to open each mailbox to check if it’s using the email address that you need.

You can add email addresses to groups or users in different locations, but they all come together in your Exchange Online server. So that is the place where we are going to search.

We are going to use the new Exchange Online PowerShell Module for this, if you haven’t used it before, then you can follow this short guide to install it and connect to Exchange Online. The advantage of the new module is that you can easily connect to different tenants and it supports MFA.

Finding Emailaddresses with PowerShell

All the email addresses of a mailbox are listed in the EmailAddresses property of the EXOMailbox cmdlet. We can search for any email address by applying a filter on the EmailAddresses. The advantage of the filter is that we can also use wildcards.

Finding Emailaddresses with PowerShell

Let’s start simple and search for a specific email address. In the example, we are going to look up who is using the [email protected] email address.

# Make sure you are connected to Exchange Online

# Search for the emailaddress
# -eq stands for equels, so the emailaddress must be exactly the same as the given string
Get-EXOMailbox -filter {EmailAddresses -eq "[email protected]"}

The result is one mailbox that contains the emailaddress that we are looking for.

Find user with email address powershell office 365

Using wildcards

Wildcards allow you to search on a part of the email address. In PowerShell, you can use the * as a wildcard token, which can be placed anywhere in the string.

Let’s say we want to find all mailboxes that have an email address that contains the word support. We will be using a wildcard in front and after the word Support. Note that we are not using the -eq operator but the -like operator.

When you expect multiple results it is most useful to format the output in a table with the ft cmdlet

# Get all mailboxes that contain the word support
Get-EXOMailbox -Filter {EmailAddresses -like "*support*"} | ft
find email address powershell exchange online

One downside of the format-table output (ft) is that not all properties will fit on your screen. To solve this you can select only the fields that you need, autosize the table and wrap the lines.

Get-EXOMailbox -Filter {EmailAddresses -like "*support*"} | 
ft -Property DisplayName,RecipientType,Identity,EmailAddresses -AutoSize -Wrap
find email address powershell office 365

Powershell List all Email Addresses and Aliases

Using this principle we can also get a list with all email addresses and aliases and export it to a CSV file for example.

Getting the list with email addresses is a bit more difficult because the EmailAddresses field also contains the SPO (used for SharePoint Online features) and SIP addresses. So we need to filter those out.

By using an expression we can filter the EmailAddresses field and select only the SMTP address. The operator -clike is a case sensitive like operator.

Get-EXOMailbox | 
Select-Object DisplayName,RecipientType,PrimarySmtpAddress, @{Name="Aliases";Expression={$_.EmailAddresses | Where-Object {$_ -clike "smtp:*"}}}
Export Emailaddresses office 365 powershell

As you can see in the results, the aliases contain a prefix smtp:. We want to remove those as well before we export the results to a csv file. The -join joins multiple aliases together with a comma between them.

Get-EXOMailbox | 
Select-Object DisplayName,RecipientType,PrimarySmtpAddress, @{Name="Aliases";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp:*"} | 
ForEach-Object {$_ -replace "smtp:",""}) -join "," }}
Powershell List all Email Addresses and Aliases

If you want to export the results to excel, then you only need to add Export-Csv c:\path\filename.csv behind it:

Get-EXOMailbox |
Select-Object DisplayName,RecipientType,PrimarySmtpAddress, @{Name="Aliases";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp:*"} |
ForEach-Object {$_ -replace "smtp:",""}) -join "," }} | 
Export-Csv c:\temp\emailaddresses.csv

Return more then 1000 results

By default, the results are limited to 1000 records. If you have more then 1000 mailboxes then add —ResultSize unlimited after Get-ExoMailbox:

Get-EXOMailbox -ResultSize unlimited

Wrapping up

I hope you found this article useful. If you have any questions, just drop a comment below. You may also like the following related articles:

Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.

Leave a Comment