Pro-Exchange,Lync & Office 365
Belgian Microsoft Unified Communications Professionals
Microsoft Exchange Server, Microsoft Lync Server & Office 365
Script: bulk replace domain for mail contacts


A while back, I came across the following problem:

The client has quite a lot of external contacts from partner companies (inevitably there are multiple contacts from the same external company).
One of the partner companies changed its name (due to a merger) and therefore also changed their email domain.

The client was looking for a solution that allowed changing all email addresses for that partner company without having to go through them manually.

I decided to write a little script and this is the result:

$contacts = Get-MailContact | Where {$_.PrimarySmtpAddress –like “*@olddomain}

foreach($contact in $contacts){
     $newmail = $contact.primarysmtpaddress.tostring()
     $newmail = $newmail -replace "olddomain","newdomain"
     Get-MailContact $contact | Set-MailContact -primarysmtpaddress $newmail -externalemailaddress $newmail



Posted 08-23-2011 8:29 by Michael Van Horenbeeck