Legacy E-mail Addresses
Have you inherited an environment filled with out of date or obsolete elements or simply just had so many changes that some parts fell through the cracks? If so, you may be looking for ways to clean it up a bit. The following tackles one of those issues where you have legacy E-mail addresses remaining in your environment after a business or brand change.
Scenario: Years of change
My company has gone through many acquisitions and changes over the last several years. Throughout the process, some of the SMTP domain names in question are no longer owned by us, and as such have been removed from Exchange 2007's Accepted Domains and from the E-mail Address Policies. The problem is, removing them from the Accepted Domains and from the E-mail Address Policies does not remove their associated e-mail addresses from the users' mailboxes. This leaves us with several obsolete email addresses being associated with the mailboxes.
For instance, Company A sells off its branch with a branded domain called OLDDOMAIN.com. Company A no longer owns that brand and should therefore remove OLDDOMAIN.com from its Exchange environment entirely.
The following screenshot shows what it looks like before the script runs:
What can you do?
Since there is no built-in functionality to clean off the old domain name from the users' list of E-mail Addresses (also called ProxyAddresses), we can go into each mailbox and manually remove the old address, or we can use a PowerShell script to take care of them all at once.
In the attached code example, we will make the following assumptions:
You want to run this against every mailbox in the domain.
You have Exchange Org admin rights or at least have been delegated rights to manage the mailboxes in question.
You are running this from the Exchange Management Shell.
You will replace OLDDOMAIN.com with the actual SMTP domain name you want to clean from the e-mail addresses.
#Get all mailboxes into an Array
$mbxs = @(get-mailbox -Resultsize Unlimited)
#Iterate through each mailbox
foreach ($mbx in $mbxs)
#Create two copies of the email addresses in the returned mailbox
$CurrentList = $mbx.emailaddresses
#the second copy is the one where the changes will take place.
$NewList = $mbx.emailaddresses
#Iterate through each address in the address list.
foreach ($Address in $CurrentList)
#see if the current address matches the domain you are wanting to remove
if ($Address.tostring() -match "OLDDOMAIN.com")
#If the match is found, remove that address from the list.
$NewList -= $Address
#Overwrite the old list with the new list.
set-mailbox $mbx -emailaddresses $NewList
This script worked perfectly for our environment and saved me from having to search through over 4000 mailboxes and manually change the ones I found. After running the script, I was able to confirm that the OLDDOMAIN.com SMTP address had indeed been removed.