Remove Email addresses using PowerShell | Office 365 | Part 12#13 5/5 (3) 7 min read

In this article, we review the subject of removing (deleting) E-mail address by using PowerShell.
The subject of – “removing existing E-mail address” using PowerShell can cause some confusion because there are two types of “deletion operations” that depend on the specific PowerShell command syntax that we use.

The two methods for removing (deleting) E-mail address using PowerShell

The task of deleting the email address using PowerShell can be implemented in two ways:

  1. Replacing E-mail address with another E-mail address.
  2. Deleting E-mail address from existing E-mail addresses “pool.”

1. Replacing E-mail address with another E-mail address

The first method which I described as “replacing” existing E-mail address with a New E-mail address, can be a bit tricky.

When using, this option the NEW E-mail address “overrides” existing E-mail address (deleting existing E-mail address) and replace them with the NEW E-mail address that we provide.

The rules of – “deleting existing E-mail address” are not so clear because in this scenario the operation of “deleting E-mail address” Is not created on purpose.

When we use the PowerShell cmdlet – Set-Mailbox, and provide the “NEW E-mail address” that we want to add to specific Exchange Online recipients, PowerShell will remove any existing E-mail address and then add the NEW E-mail address.

For example, in an Office 365 environment, I experienced a significant number of times, a scenario in which the PowerShell command that adds the NEW E-mail address, delete even non-SMTP E-mail address such as SIP address and in additional the “onMicrosoft” built-in E-mail address.

To demonstrate this concept, let’s use the following example:

In the following screenshot, we can see the E-mail addresses of an Exchange Online recipient
named – Christina.

Christina has 1 Primary E-mail address + 2 Alias E-mail addresses.

Replacing E-mail address with other E-mail address -01

We want to replace the primary E-mail address of Christina to the following E-mail
address – Christina-NEW01@o365info.com

To replace the existing primary E-mail address, we use the following PowerShell command:

In the following screenshot, we can see the result:

The NEW E-mail address replaces the existing primary E-mail address and saves the former primary E-mail address as – Alias E-mail address.

Notice that the Alias E-mail address was removed!

Replacing E-mail address with other E-mail address -02
2. Deleting E-mail address from an existing E-mail addresses “pool”

The second method for removing E-mail address (which I prefer to use), is implemented by using the PowerShell parameter “@{remove

When we use the PowerShell parameter – “@{remove”, we “tell” PowerShell what is the exact E-mail address that we want to remove (delete).

To delete a specific E-mail using the PowerShell parameter – “@{remove”, we need to use the following PowerShell command syntax.

PowerShell command syntax

PowerShell command example

To demonstrate this concept, let’s use the following example:

In the following screenshot, we can see the E-mail addresses of an Exchange Online
recipient named – Christina

Christina has 1 Primary E-mail address + 2 Alias E-mail addresses.

Deleting E-mail address from existing E-mail addresses using @ remove-01

We want to remove the following E-mail address – Christina-Alias02@o365info.com from Christina’s mailbox.

For this purpose, we use the following PowerShell command.

In the following screenshot, we can see the result, the Alias E-mail address was removed, and all the rest of Christina E-mail addresses did not change in any way.

Deleting E-mail address from existing E-mail addresses using @ remove-02

Note – you can read more information about the “behavior” of the PowerShell cmdlet – Set-Mailbox when adding E-mail address in the article – Adding Email addresses using PowerShell | Office 365 | Part 3#13

Quick tip

Another syntax option that we can use for removing E-mail address is implemented by using the “minus” () characters instead of the term “remove.”

We will need to use to enclose the minus character in quotes.

For example:

Remove all E-mail addresses that have a specific domain name | Bulk mode.

In this section, I would like to review a scenario, in which we need to remove (delete) E-mail address that has some specific characters such as – Domain name suffix.

This operation in which we address many “objects” (Exchange Online recipients) at the same time and perform a specific update, such as – removing E-mail address, described as “Bulk.”

Before we continue with the exact PowerShell syntax, it’s very important for me to “warn you” because when using the option of “Bulk” and especially when relating to the task of – deleting E-mail addresses, we should plan carefully our steps, test the result of the PowerShell bulk command, use the option of “Whatif” and so on.

Note – you can read more information about the “Whatif” option in the article – Adding Email addresses using PowerShell – Bulk mode | Office 365 | Part 4#13

Scenario description

Our company owns two public domain names: o365info.com and o365pilot.com.
Following a legal problem, we will need to remove the domain name – o365pilot.com and deleted each of the E-mail addresses that their suffix includes the domain name – o365pilot.com

The characters of our organization E-mail address infrastructure are:

  • Each of the organization recipients, have a primary E-mail address that uses E-mail address based on the domain name o365info.com.
  • Each of the organization recipients, have an additional Alias E-mail address that has the “other” company domain name such as –o365pilot.com

We need to “write” a PowerShell bulk command that performs the following tasks:

  1. Run a Loop process on the existing Exchange Online recipient.
  2. Search and find an E-mail with a specific domain name suffix.
  3. Delete this E-mail address.

Let’s use the following scenario:

The name of the domain that we want to remove is configured via the variable – $RemoveDomain.

The information about all existing Exchange Online mailboxes will be saved in the variable named- $AllMailboxes.

The variable $AllMailboxes content, is created by using a PowerShell query that looks for all the recipients who have E-mail address that include the domain name – o365pilot.com.

Then we run a PowerShell ForEach statement that will loop via the Exchange Online mailboxes array and run the following tasks on each of the Exchange Online mailboxes that appear in the array:

  • Verify if the Exchange Online mailboxes have E-mail address with the domain name suffix – o365pilot.com.
  • If the answer is “Yes” remove each of the E-mail addresses that include the domain name – o365pilot.com.
  • “Jump” to the next Mailbox in the list.

PowerShell command example


For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article,
in a “Menu Based” PowerShell Script.

You are welcome to download the PowerShell script and use it.
Download -o365info PowerShell Script

Manage E-mail address using PowerShell script
In case that you need instructions about – how to use the Manage E-mail address PowerShell script menu, you can read the fowling Article.


Now it’s Your Turn!
It is important for us to know your opinion on this article

Restore Exchange Online mailbox | Article series index

Print Friendly, PDF & Email

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

Leave a Reply

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