Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

Bulk change of external email addresses for Mail Contacts - Exchange 2007

Assuming this is going to need powershell.

We have a LOT of mail contacts in the form of user@abc.com. abc.com is changing to xyz.zom so we want to be able to identify and change all of them. Invididually would be a problem.

Can anyone help with necessary commands to to do this?
paul williams
paul williams
2 Solutions
Raheman M. AbdulCommented:
paul williamsAuthor Commented:
Thanks but first I need to know how to get a list of contacts with abc.com as their smtp email address before I can change them.
Will SzymkowskiSenior Solution ArchitectCommented:
Use the following powershell scripts to accomplish exactly what you need.

import-module activedirectory
add-pssnapin microsoft.exchange.management.powershell.admin
Get-MailContact -resultsize "unlimited" | select Alias | out-file "c:\mailcontacts.csv"

Open in new window

This will give you all of the mail contacts in your environment, and export them to a CSV file.

From there do the following...
- open the CSV remove the second line -----------------------------
- create a second column called NewAddress
- make sure that the CSV file is constructed like below...
Alias             NewAddress
bobprince   bprice@xyz.com

Then use the next powershell script to change each ExternalEmailAddress respectively...
import-module activedirectory
Add-PSSnapin microsoft.exchange.management.powershell.admin
$UserList = import-csv "c:\mailcontacts.csv"
foreach ($Contact in $UserList) {
Get-MailContact -Identity $Contact.Alias | Set-MailConact -ExternalEmailAddress $Contact.NewAddress -Confirm:$False

Open in new window

This will then go through the csv and modify each mail contact respectively.

You only need this one line:
Get-MailContact -ResultSize Unlimited | Where {$_.WindowsEmailAddress -match 'abc.com' } | Foreach {Set-MailContact $_.WindowsEmailAddress  $_.WindowsEmailAddress  -Replace "abc" "xyz"}

Open in new window

To first check the contacts:
Get-MailContact -ResultSize Unlimited | Where {$_.WindowsEmailAddress -match 'abc.com' } | ft Name, Alias, WindowsEmailAddress 

Open in new window


Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now