Remove Old Email Addresses from Exchange 2010

If you’ve ever changed an email address policy in Exchange, you are aware that old addresses from previous policies are not deleted.  This is by design and intentional but what if you made a mistake in your policy and need to remove hundreds of invalid addresses from accounts.  For instance… you created a policy for [firstinitial.lastname@domainname.org] when you really meant to set an underscore  as a separator instead of the period.

The following script will use a regular expression to find all email addresses containing periods between firstinitial and lastname then remove them.

$allmailboxes = get-mailbox
$allmailboxes |% {$a = $_.emailaddresses; $b = $_.emailaddresses; foreach ($e in $a) {if ($e.tostring() -match “[a-z]+\.[a-z]+@domainname.org”) {$b -= $e;}}$_ | set-mailbox -emailaddresses $b}

By simply editing the regular expression in this script, you can search for all kinds of different combinations of addresses and remove them from your users mailboxes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s