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.
Who is Participating?
GusGallowsConnect With a Mentor Commented:
For the public folder, if you have the CN of the public folder, you can do the following:

$newsmtp = "" #replace with actual smtp address you want to use
$PFCN = "PublicFolderCN" #replace "PublicFolderCN" with the CN of the public folder you wish to change

$PF = Get-MailPublicFolder -Identity $PFCN

$PF.EmailAddresses += $newsmtp

$PF | Set0MailPublicFolder

Open in new window

Bryan ButlerCommented:
This link might help:  Looking for a Powershell cmdlet to change Contacts email addresses
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 = ''
#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 = "" #replace with the OU you want to work with
#specify the domain of the new SMTP address you want to change it to
$NewDomain = ""
#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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.