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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bryan ButlerCommented:
This link might help:  Looking for a Powershell cmdlet to change Contacts email addresses
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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 = ''
#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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.