Skip to content
September 9, 2010 / dw

Using powershell to change email address suffixes

Home to atthedatacenter.com#This changes current email address to a different suffix. It assumes there is only one address with a different suffix.
Get-Mailbox -ResultSize Unlimited -Filter “emailaddresses -like ‘*mydomain.com” | foreach {
$user = $_.alias
$mssmtp = $_.emailaddresses -like ‘*myNewdomain.com’
$address = $mssmtp[0]
$newsmtp = $address -replace “smtp:”
set-mailbox -identity $user -primarySMTPaddress $newsmtp

Clear-Variable user
Clear-Variable mssmtp
Clear-Variable address
Clear-Variable newsmtp   
} #This pulls users from a list and changes the current email to the exact same with a different suffix.$r = (get-content “c:scriptsflipSMTP.txt”)
foreach ($line in $r) {Get-Mailbox -ResultSize Unlimited -Filter “alias -like ‘$line’ -and emailaddresses -like ‘*mydomain.com'” | foreach {
$user = $_.”alias”
#$mssmtp = $_.emailaddresses -like ‘*myNewdomain.com’
$address = $_.primarySMTPaddress
$newsmtp = $address -replace “smtp:”
$newsmtp = $address -replace “mydomain.com”,”myNewdomain.com”
set-mailbox -identity $user -primarySMTPaddress $newsmtpClear-Variable user
Clear-Variable mssmtp
Clear-Variable address
Clear-Variable newsmtp   
}}  Now for mail contacts:#This pulls users from a list and changes the current email to the exact same with a different suffix.$r = (get-content “c:scriptsflipSMTP.txt”)
foreach ($line in $r) {Get-mailcontact -ResultSize Unlimited -Filter “displayname -like ‘$line’ -and windowsemailAddress -like ‘*old.domain.com” | foreach {
$user = $_.”displayname”
$address = $_.primarySMTPaddress
$newsmtp = $address -replace “smtp:”
$newsmtp = $address -replace “old.domain.com”,”newdomain.com”
set-mailcontact -identity $user -primarySMTPaddress $newsmtp
set-mailcontact -identity $user -externalemailaddress $newsmtp
Clear-Variable user
#Clear-Variable mssmtp
Clear-Variable address
Clear-Variable newsmtp   
}}Hope it helpsdwHome to atthedatacenter.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: