Exchange Public Folder migration code

Published On: 2019-01-21By:

This last week John Morehouse and I did a significant office migration with one of our clients. As part of the migration, we decided to move their public folders from Exchange 2016 to Office 365 so that their public folders were hosted in the same place as their mailboxes; allowing us to

https://www.flickr.com/photos/spidere/5101386622/in/

https://www.flickr.com/photos/spidere/5101386622/in/

decommission Exchange as the public folders were the last thing on the servers.

Microsoft has some documentation on your the migration, but the Microsoft documentation is rather lengthy and takes a long time to go through. We only had about 400 Megs of data to move, most of which is contacts and calendars. Instead of going through the rather lengthy process to move such a small amount of data, we instead opted to export the data through Outlook and reimport it to Office 365. This process required that we reset the permissions on the data after the migration.

The first thing we needed to do was to export the current permissions from the on-prem Exchange 2016 server. The export of the permissions was done via the Get-PublicFolderClientPermission PowerShell CmdLet. We combined this with Export-CSV as so.

Get-PublicFolderClientPermission “\” | select of user, identity, accessrights | format-table -width 500 | Export-Csv c:\temp\rights.csv -notypeinformation

This produced a fixed width text file that we could work with. We then opened the file in Notepad++ and did some Find/Replace operations to turn our fixed width file into a file we could more easily work with.

First, we searched for anything that has three spaces and replaced it was three {pipe} values (we had a couple of values with two spaces in them). We then did a search for {pipe}{space}{space} and replaced that value with {pipe}. We then did a search for {pipe}{space} and replaced that with {pipe}. We then ran a search and replace for {pipe}{pipe} and replaced it with {pipe}. We did this a bunch of times until there were 0 results found to the file. This case of a pipe delimited file that we could work with.

We then told Exchange to use the Office 365 version of the public folder, instead of the local version. We did this with the Set-OrganizationConfig CmdLet. Keep in mind, this CmdLet will delete all the data in your Exchange server’s Public Folder database, so make sure that you export your data from the public folder, and that you pull down your permissions BEFORE you run this.

Set-OrganizationConfig -RemotePublicFolderMailboxes $Null -PublicFoldersEnabled Local

After this was all done, we connected a PowerShell window to Office 365 and processed the text file to put the permissions back. This was done using a short PowerShell script.

$a = Get-Content C:\temp\rights2.csv
$a | foreach {
$data = $_
$arr = $data.Split(“|”)
$perm = $arr[2].replace(“{“, “”).replace(“}”, “”)
$perma = $perm.split(“,”)

$permb = [collections.arraylist]$perma

$data

Add-PublicFolderClientPermission -Identity $arr[0] -user $arr[1] -AccessRights $permb

}

This script told us what it was working on (in case there was an error), then it did the work (using the Add-PublicFolderClientPermission CmdLet). The biggest trick with this script was converting the “normal” array named $perma into the “collection.arraylist” named $permb and then using that.

This script ran for a few hours, as Add-PublicFolderClientPermission isn’t very fast, but the result was that the permissions were back where they should have been, the Public Folder was hosted in Office 365 instead of Exchange, and we were one step closer to being able to get rid of the exchange server. And most importantly, the users didn’t report a single problem after the migration was done.

Denny

The post Exchange Public Folder migration code appeared first on SQL Server with Mr. Denny.

Contact the Author | Contact DCAC

Video

Globally Recognized Expertise

As Microsoft MVP’s and Partners as well as VMware experts, we are summoned by companies all over the world to fine-tune and problem-solve the most difficult architecture, infrastructure and network challenges.

And sometimes we’re asked to share what we did, at events like Microsoft’s PASS Summit 2015.

Awards & Certifications

Microsoft Partner       Insights Sccess Award    Technology Headlines Award    Golden Bridge Gold Award    CIO Review Top 20 Azure Solutions Providers    VMWare Partner
Microsoft Certified Master    Microsoft MVP
Share via