Public Folders in Exchange allow you to store shared user data on Exchange servers in a hierarchical view. In Exchange Server 2013 and all newer versions (Exchange 2016, 2019), Public Folders are stored in mailboxes. A public folder is a special type of Exchange mailbox that can store both the public folder hierarchy and the content. This allows providing the high availability of Public Folders by placing the mailbox in a database that is a part of the Database Availability Group (DAG).
Users can access Public Folders from Microsoft Outlook (2013+), Outlook Web Access (OWA), and Outlook for Mac.
You can list Public Folders in your Exchange organization in the Exchange Admin Center (EAC) or using PowerShell:
Get-PublicFolder -Recurse -ResultSize Unlimited
The list of folders in a specific Public Folder can be displayed as follows:
Get-PublicFolder -Identity "HelpDesk" -Recurse -ResultSize Unlimited
You can view a list of the permissions assigned to users for a specific Public Folder:
Get-PublicFolderClientPermission -Identity "HelpDesk" | Select User, AccessRights
There are no built-in tools to export the content of Public Folders to PST files in the Exchange Server. Unfortunately, the PowerShell New-MailboxExportRequest cmdlet doesn’t support exporting Public Folder content to PST.
The most popular and easiest way to export the contents of a Public Folder to a PST file is the Import/ Export feature built into Outlook. Let’s take a look at how to export the Public Folder content to the PST file using Outlook.
Note. To export the contents of a public folder to a PST file, you must have Microsoft Outlook (version 2013 or newer) installed on your computer with Exchange profile configured, and the required public folders must be connected in Outlook’s configuration.
Run the Outlook and select File > Open > Import/Export.
In the window that opens, select “Export to a file” > “Next”.
Select “Outlook Data file (.PST)” on the next wizard step and click “Next”.
Select the Public Folders whose content you want to export. Check the “Include subfolder” option.
Specify the name of the PST file to which you want to upload the contents of the Public Folder and check “Replace duplicates with items exported”. Click Finish and wait for Outlook to export.
Exporting Public Folder content to PST via Outlook can take quite a long time.
If the size of the Public Folder is more than 10–20 GB, Outlook can easily crash during exporting. In this case, it is better to export the contents of the Public Folder by parts.
You can use the following PowerShell script to export Public Folder to PST. This script uses the Outlook.Application COM object to access the Public Folder, so Outlook must be installed and configured on your computer:
function Export-MailboxFolder($folder) { Begin{ $Outlook = New-Object -ComObject Outlook.Application $namespace = $Outlook.GetNameSpace("MAPI") } Process{ New-Item -Path 'D:\Backup\PublicFolder' -Name "$($folder.Name)" -ItemType Directory foreach ($f in $folder.folders) { $PSTPath = 'D:\Backup\PublicFolder' + '\' + "$($folder.Name)" $PSTName = $($f.name) + '.pst' $FullPST = $PSTPath + '\' + $PSTName $namespace.AddStore("$FullPST") $pstFolder = $namespace.Session.Folders.GetLast() [void]$f.CopyTo($pstFolder) } } End{ "Remove attached PST in Outlook" $RemPST = $Outlook.Session.Stores | Where DisplayName -EQ 'Outlook Data File' foreach ($pst in $RemPST){ $Outlook.Session.RemoveStore($pst.GetRootFolder()) } } } $PublicFolderToExport = $Outlook.Session.Folders.Item('Public Folders - Helpdesk').folders.item('All Public Folders').Folders.Item('Level-1').folders.item('Level-2').folders.item('Level-3') Export-MailboxFolder $PublicFolderToExport
3 comments
Hello Cyril Kardashevsky
Server Details:
Windows 2008R2
Exchange 2010
Client Details:
Windows 10
Office 365 Apps
Error Description:
Error appears from line 50 – 52
—————————————————————————————–
**********************
Unable to call a method on an expression that has the NULL.
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:52 characters:1
+ $PublicFolderToExport = $Outlook.Session.Folders.Item(‘Project Management …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
It is not possible to call a method for an expression that has the NULL.
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:52 characters:1
+ $PublicFolderToExport = $Outlook.Session.Folders.Item(‘Project Management …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
>> TerminatingError(New-Object) : “The COM class factory for the component with CLSID {0006F03A-0000-0000-C000-0000000046} could not be retrieved due to the following error: 80080005 Failed to start server (HRESULT exception: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).”
New-Object : The COM class factory for the component with CLSID {0006F03A-0000-0000-C000-0000000046} could not be retrieved due to the following error
could not be retrieved due to the following error: 80080005 Failed to start server (HRESULT exception:
0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:7 characters:20
+ $Outlook = New-Object -ComObject Outlook.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
New-Object : The COM class factory for the component with CLSID {0006F03A-0000-0000-C000-00000046} could not be retrieved due to the following error: 80080005 Starting the server
failed (exception of HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:7 characters:20
+ $Outlook = New-Object -ComObject Outlook.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
It is not possible to call a method for an expression that has the NULL.
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:9 characters:9
+ $namespace = $Outlook.GetNameSpace(“MAPI”)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
It is not possible to call a method for an expression that has the NULL.
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:9 characters:9
+ $namespace = $Outlook.GetNameSpace(“MAPI”)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
New-Item : An item with the specified name “C:BackupPublicFolder” already exists.
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:15 characters:9
+ New-Item -Path ‘C:BackupPublicFolder’ -Name “$($folder.Name …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceExists: (C:BackupPublicFolder:String) [New-Item], IOException
+ FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand
New-Item : An item with the specified name “C:BackupPublicFolder” already exists.
In C:UsersladminDesktopPublicFolder-Export-MailboxFolder.ps1:15 characters:9
+ New-Item -Path ‘C:BackupPublicFolder’ -Name “$($folder.Name …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceExists: (C:BackupPublicFolder:String) [New-Item], IOException
+ FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand
Remove attached PST in Outlook
—————————————————————————————–
I am trying to run this script directly from a domain joined Windows 10 client with Office365 Apps (32bit). Unfortunately it does not work. I have adjusted the path to C:BackupPublic Folders but that didn’t help either.
Can you possibly comment exactly the parts of the script to customize this way with the needed content?
Thanks for feedback
Hi,
I’m getting the same errors, any luck fixing this anybody?
Hi Cyril, could you expand on how you are constructing the variable: $PublicFolderToExport = $Outlook.Session.Folders.Item(‘Public Folders – Helpdesk’)…..
what are the elements level-1, level-2 etc… I’m trying to translate this to my environment where I have a structure:
\All Public Folders
\TestFolder1
If I merely substitute your value of ‘Public Folders – Helpdesk’ with ‘TestFolder1’ I get an error… so I’d like to understand how that folder path is being constructd & passed to the function…
Many thanks!