Apr 5, 2010

How to add a new domain to all email addresses in Active Directory

So recently one of our System Administrators had been tasked with updating all of our users to a new domain that we bought. He then though, “How do I add a new domain to all email addresses in Active Directory using PowerShell?” This is when he though, who better to help me do some scripting but, [queue heroic music] ‘FreedomChicken’! The ever friendly developer who with his powers of Debugging and Google Searching can single handily defeat evil Bugs and Hang-ups in applications and scripts. Now with Freedom chicken on the job the two were able to defeat this evil foe in a quick and timely manner. The result of this victory will be as follows.

PowerShell Script:

get-mailbox %username% | foreach {

[string]$smtpaddress = Get-mailbox $_ | select primarysmtpaddress

$addressarray = $smtpaddress.split("@")

$addressarray1 = $addressarray[1].split("=")

[string]$newmail=$addressarray1[1]+="@NEWDOMAIN.com"

$_.EmailAddresses+=$newmail

$_

} |Set-Mailbox




Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | stopping spam