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:

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

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.

We want to replace the primary E-mail address of Christina to the following E-mail address – [email protected]

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

1

Set-MailboxChristina-EmailAddressChristina-NEW01@o365info.com

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!

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.

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.

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:

Run a Loop process on the existing Exchange Online recipient.

Search and find an E-mail with a specific domain name suffix.

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.

The next article in the current article series

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

Restore Exchange Online mailbox | Article series index

Please rate this

Sample rating item

Summary

Article Name

Remove Email addresses using PowerShell | Office 365 | Part 12#13

Description

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.