Mike Shellenberger's blog

Navigating the Digital Frontier: End-User Tech Insights

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.

Published by

Leave a comment