Exchange – Apply Public Folder Permission Import via Import-CliXML

exchangeimportmicrosoft-office-365permissionspublic-folders

I did run into the situation that I lost all my public folder permissions which were assigned via groups.

Before the migration started from our MSEX2016 server to Office 365, all the permissions got exported to a XML file, what I think (described on this Microsoft page) happened with the following command:

Get-PublicFolder -Recurse -ResultSize Unlimited | Get-PublicFolderClientPermission | Select-Object Identity,User,AccessRights -ExpandProperty AccessRights | Export-CliXML OnPrem_PFPerms.xml

The output file "OnPrem_PFPerms.xml" has about 5 GB. That sounds a lot to me for permissions only on a about 300 GB PF structure, but maybe is its huge size cause by the complexity of the XML format. 7-Zip compression brings it down to 25 MB, means there is a lot of redundant data in it.

On our MSEX2010 which got migrated to MSEX2016 before is a "Legacy_PFPerms.xml" file with about 500 MB.

What would be the proper PowerShell command to apply all the permissions from the XML file to the public folder structure on the Office 365 / Exchange online?

I guess Import-CliXML would do the job somehow, but I am not that familiar with PowerShell to build the right command.

Best Answer

Finally the following PowerShell script allowed me to apply all the permissions from the XML file to the public folder structure. Thanks to Ivan_Wang who led me to the right direction with his answer.

$pfs = Import-Clixml -Path OnPrem_PFPerms.xml

foreach($pf in $pfs)
{
Add-PublicFolderClientPermission -Identity ("\" + $($pf.Identity.MapiFolderPath -join "\")) -User $pf.User.DisplayName -AccessRights $pf.AccessRights[0].ToString()
}

Is is also possible to split that up in multiple PowerShell sessions to apply the changes faster since it runs pretty slow.

  1. PS session: foreach($pf in $pfs[0..2000]) ...

  2. PS session: foreach($pf in $pfs[2001..4000])...

...

Do not run too many sessions at one, otherwise it will interrupt the connection to Exchange Online with the following message: The request is not serviced on the server. Your request is too frequent.