How to Get PFs with More Than One Primary SMTP suffix and Change Them for 1,000+ Public Folders

Greetings.

I need to get all mail-enabled Public Folder mailboxes ending either in @abc1.com and ALSO all PFs ending in @abc2.com, for example.
Then I need to change their Primary SMTP address to @abc3.com.

I would like to get a PS script (or even VB script if necessary) to do this, as I don't think it is possible for an Email Address Policy to find all Public Folders and change them based on such a filter.

I started out focused on this cmdlet: Get-MailPublicFolder to use it to get all Public Folders whose Primary SMTP Suffix "ending in" or -eq or -like "@abc1.com"

Then I switched focus to this cmdlet, realizing that I nee to possibly get all mailboxes first, then filter for Public Folder "type", but still need to filter ALSO on Primary SMTP Suffix.
Get-Mailbox -PublicFolder | ? {$_.PrimarySmtpAddress -like "@abc1.com" OR "@abc2.com"} | Set-Mailbox -PrimarySmspAddress "@abc3.com"

Am I getting anywhere close to this working?
I thought I was for a minute, but now does not seem so.

Thank you for any suggestions.
KontrarianKid
kontrariankidAsked:
Who is Participating?
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.

Amit KumarCommented:
Use below one to export data first, please create a data folder in C Drive

Get-MailPublicFolder -resultsize "unlimited" -filter {PrimarySmtpAddress  -like "*@abc1.com"} | Select *Name*,  PrimarySmtpAddress  | export-csv c:\data\abc1publicfolder.csv

Get-MailPublicFolder -resultsize "unlimited" -filter {PrimarySmtpAddress  -like "*@abc2.com"} | Select *name*, PrimarySmtpAddress  | export-csv c:\data\abc2publicfolder.csv

Open in new window


Once you get list then copy all Primary SMTP address and change domain of each e-mail address. copy only e-mail address in a file and save it as csv.

so you will have two files:

abc1to3.csv will have e-mail address those are actually were replaced from @abc1.com to abc3.com

abc2to3.csv will have e-mail address those are actually were replaced from @abc2.com to abc3.com

now copy below code and save it as ps1 and copy both csv file in c drive in folder named data, then run ps1 in EMS and see the changes.

$abc1 = Get-MailPublicFolder -resultsize "unlimited" -filter {PrimarySmtpAddress  -like "*@abc1.com"}
$abc2 = Get-MailPublicFolder -resultsize "unlimited" -filter {PrimarySmtpAddress  -like "*@abc2.com"}
$abc1to3 = get-content c:\data\abc1to3.csv
$abc2to3 = get-content c:\data\abc2to3.csv
foreach ($abc1a in $abc1)
{Set-MailPublicFolder -Identity $abc1a -PrimarySmtpAddress $abc1to3}
write-host "abc1 batch is completed"
foreach ($abc2a in $abc2)
{Set-MailPublicFolder -Identity $abc2a -PrimarySmtpAddress $abc2to3}
write-host "abc2 batch is completed"

Open in new window

0

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
kontrariankidAuthor Commented:
Thank you Amit.
0
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
Powershell

From novice to tech pro — start learning today.

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.