PowerShell command to export public folder to PST in Exchange 2019/2016/2013/2010

PowerShell command to export public folder to PST in Exchange 2019/2016/2013/2010


by Analytics Insight


March 28, 2022

Users can use PowerShell for efficient transfer of public folders to PST

Public folders are special mailboxes in on-premises Exchange Server used to share information between users or people in a workgroup or organization. The public folder provides a common space for users to collect, organize, and share documents or information and facilitate collaboration.

Users with access to public folders can see content stored there by other users and vice versa. The public folder can be accessed from Outlook for Mac, Outlook for Windows, and Outlook Web App (OWA).

PowerShell

When added as a member of a distribution group, public folders can also be used to archive emails sent from mail-enabled public folders. When an email is sent to the group, a copy of the email is automatically saved to the public folder.

In an on-premises Exchange server, there are mainly two types of public folder mailboxes.

  • Main hierarchy mailbox

Primary hierarchy mailbox or public folder primary hierarchy mailbox is the first public folder created in the Exchange server. Also, it is the only writable copy of the public folder hierarchy.

  • Secondary hierarchy mailbox

All public folder mailboxes created after the primary hierarchy mailbox are called secondary hierarchy mailboxes. These public folder mailboxes are read-only copies of the hierarchy. Therefore, all changes to the public folder hierarchy redirect to the main hierarchy mailbox and are replicated to other public folder mailboxes to avoid conflicts.

In this article, you will learn the process of exporting public folders to PST format in Exchange Server 2010, 2013, 2016 and 2019 using PowerShell command. Moreover, we have also mentioned an advanced solution to quickly export all public folders to PST, Office 365 or another live Exchange server directly.

How to export public folders to PST in Exchange Server?

To export user mailboxes to PST, you can use New-MailboxExportRequest PowerShell cmdlet in Exchange Server 2010 SP1 or later versions. However, there is no PowerShell cmdlet to export public folders to PST in Exchange Server 2010, 2013, 2016 or 2019.

If you need to export public folders to PST via PowerShell, you need to create a PowerShell script that uses the Outlook application COM object to extract the public folders in PST format. You can also use Outlook’s Import/Export Wizard to export public folders to PST format.

If there are multiple public folders to export, the user account must have access to all of those public folders. Moreover, you have to manually select and export them in PST format. In a nutshell, Outlook application is required on Windows PC or your Exchange server to export public folders to PST format.

You can also use EDB to PST converter software, such as Stellar Converter for EDB, to overcome the limitations of the manual method and PowerShell script. The software helps you extract and export all public folders at once from your Exchange Server Database (EDB) to PST format in just a few clicks. You can also use the software to directly export public folders to Office 365 or Exchange Server live.

Steps to Use PowerShell to Export Public Folders to PST

To create a PowerShell script to export public folders to PST, open Notepad and paste the following code.

function Export-MailboxFolder($folder)

{

To start{

$Outlook = New-Object -ComObject Outlook.Application

$namespace = $Outlook.GetNameSpace(“MAPI”)

}

To treat{

New Item -Path ‘C:PFBackupPublicFolders’ -Name “$($folder.Name)” -ItemType Directory

foreach ($f in $folder.folders) {

$PSTPath = ‘C:PFBackupPublicFolders’ + ” + “$($folder.Name)”

$PSTName = $($f.name) + ‘.pst’

$FullPST = $PSTPath + ” + $PSTName

$namespace.AddStore(“$FullPST”)

$pstFolder = $namespace.Session.Folders.GetLast()

[void]$f.CopyTo($pstFolder)

}

}

To finish{

“Delete attached PST files 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

PowerShell

Note: Replace C:PFBackupPublicFolders (highlighted in code) with the desired folder location to save exported public folder files in PST format.

  • Press CTRL + S or go to File > Save, then choose a location where you want to save the PowerShell script.

PowerShell

  • From the drop-down list, choose All Files and enter ps1 as the script name.
  • Close Notepad and navigate to the location where you saved the ps1 script.
  • Right click on the script and choose Run with PowerShell.

PowerShell

  • If prompted, type Y and press Enter to confirm and run the script.
  • Wait for a while and then check the folder for public folders exported as PST files.

PowerShell

To note: Make sure Outlook is installed and configured with the user or administrator account that has access to the public folders you want to export to PST.

Conclusion

In Exchange 2019, 2016, 2013 and 2010, there is no PowerShell cmdlet to export public folders from Exchange mailbox database to PST format. If you need to export the public folders to PST, you can use the Outlook Import Export wizard or a PowerShell script we mentioned in this article. It’s just that you have to repeat all the steps several times until you export all your public folders. Also, there is no control over what mail items you want to export from public folders. To avoid such a scenario, use EDB to PST converter software to export all your mailboxes to PST, Office 365 or Live Exchange with peace of mind.

Share this article

Do the sharing

Comments are closed.