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
Mike Shellenberger
With over 20 years of experience in implementing and supporting technical solutions, I am passionate about leveraging Microsoft technologies and devices to make a tangible impact on end users. My expertise spans a wide range of Microsoft products, including Windows clients, Intune, Microsoft 365, Windows 365, and Configuration Manager. I have a proven track record in designing, deploying, and managing complex IT infrastructures, ensuring seamless integration and optimal performance.
I am dedicated to the digital workspace technology community, where I actively contribute and continuously learn to stay at the forefront of industry advancements. My technical skills also encompass identity/authentication technologies, endpoint security, and cloud computing, enabling me to deliver comprehensive solutions that enhance user productivity and satisfaction.
Outside of my professional life, I am an avid homebrewer, amateur radio enthusiast, beekeeper and runner. I enjoy balancing my technical pursuits with these hobbies, which keep me grounded and inspired. I reside in the Lancaster, PA area with my wife and two kids, where we cherish our community and the opportunities it provides.
Leave a comment