Easily search for email addresses in Office 365

Who is using that one particular email address as an alias? Main email addresses are easy to find in the O365 GUI. Aliases are not, and you don’t want to open each mailbox to check if it’s using the email address you need. Using Powershell, you can easily search for email addresses in your Exchange Online environment.

As we are looking for email addresses, we need to connect to the Exchange Online environment. You can find instructions on how to connect here.

Example of Get-ExoMailbox output

In the following example you will see how Exchange is storing email addresses:

Get-ExoMailbox example

The attributes of the mailboxes (demo@domain.com) always contain “EmailAddresses”. If you are syncing with your on-premise Active Directory it is good to know that this is called “ProxyAddresses” in there. The proxyAddresses attribute in Active Directory is a multi-value property, just like the EmailAddresses field can hold multiple entries.

Using powershell to search in Exchange Online

To search in the EmailAddress field for a specific value (for example, the “findme” alias) you can use the following command to search for an exact match:

Get-EXOMailbox -filter {EmailAddresses -eq "findme@domain.com"}

If you want to search for parts of the mailaddress, you can use a wildcard like this:

Get-EXOMailbox -Filter {EmailAddresses -like "*findme*"}

For an advanced list of mailboxes and all aliases, the following line will generate a nicely formatted output.

Get-EXOMailbox -ResultSize unlimited | 
Select-Object DisplayName, PrimarySmtpAddress, @{Name="Aliases";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp:*"} | 
ForEach-Object {$_ -replace "smtp:",""}) -join "," }}