Link to home
Start Free TrialLog in
Avatar of DCMA
DCMAFlag for United States of America

asked on

Change primary mailbox smtp email address using exchange power shell 2007

trying to put a script together for below
1. I would like to change the primary Mailbox smtp email address for all users within a specific OU
2. I would like to change an smtp email address for a mail enabled public folder using Power shell

thanks for your input.
Avatar of Bryan Butler
Bryan Butler
Flag of United States of America image

This link might help:  Looking for a Powershell cmdlet to change Contacts email addresses

http://social.technet.microsoft.com/Forums/en/exchangesvradmin/thread/fa94c2eb-3259-4788-883e-abeb5ed0956b
ASKER CERTIFIED SOLUTION
Avatar of GusGallows
GusGallows
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Last line should have been:
$PF | Set-MailPublicFolder
On the Changing of the primary smtp address for the mailbox, you can do the following:
#specify a domain controller to work with
$dc = 'domaincontroller.domain.com'
#Create an output file to capture the results
$Output = "output.txt"
Out-File $Output -InputObject "OldPrimarySMTPAddress`tNewPrimarySMTPAddress"
#specify the OU you wish to pull the users from
$OU = "domain.com/IT/Users" #replace with the OU you want to work with
#specify the domain of the new SMTP address you want to change it to
$NewDomain = "NDomain.com"
#get a list of all mailboxes in the OU
$list = get-mailbox -OrganizationalUnit $OU -resultsize Unlimited -DomainController $DC
#Iterate through the list
foreach ($user in $list)
{
	$mb = Get-mailbox $user -DomainController $dc
	#capture current primary smtp address
	$SMTP = $mb.PrimarySmtpAddress
	[string]$Local = $SMTP.Local
	[string]$OldDomain = $SMTP.Domain
	[string]$CPSMTP = $Local + "@" + $OldDomain
	#captur new primary smtp address
	[string]$NPSMTP = $Local + "@" + $NewDomain
	#capture the old and the new SMTP addresses to the output file
	[string]$iobject = $CPSMTP + "`t" + $NPSMTP
	Out-File $Output -InputObject $iobject -Append
	#set the new primary smtp address on the mailbox and remove the flag to use the email address policy (if you do not do this, the email address will revert to whatever the policy is set to)
	Set-Mailbox $user -PrimarySmtpAddress $NPSMTP -EmailAddressPolicyEnabled $false 
}

Open in new window

I would add -domaincontroller $DC to the set mailbox command too just to be sure you are working on the same domain controller you pulled the users from. So the line should read:
Set-Mailbox $user -PrimarySmtpAddress $NPSMTP -EmailAddressPolicyEnabled $false -domaincontroller $DC