Exchange 2016, 2013, 2010 mailbox backup by export to PST (PowerShell)
[Update]: This post was updated on January 24, 2018.

An email organization lives and dies by mailbox backups. Unfortunately, all Microsoft Exchange versions, including Exchange 2016, come with limited brick-level backup capabilities. Basically, the only available granular option is an export to PST files. This can be done via Outlook (obviously), PowerShell and in some cases also via Exchange Management Console / Control Panel. In this article I discuss the options available via PowerShell in: Exchange 2016, Exchange 2013 and Exchange 2010.
Note: To export Exchange 2007 mailboxes to PST files use the Export-Mailbox cmdlet. If you are using Exchange Online, consult this article.
Single mailbox export to PST file
Exporting mailbox contents to a PST file is achieved using the MailboxExportRequest cmdlet. It has only 2 obligatory parameters: –FilePath – defines the network share path of the PST file to which you want to export the data; and –Mailbox – defines the Alias, SMTP address or Display name of the mailbox you will export. Requirements:
- The user performing the export must be a member of a role group which has the Mailbox Import Export role added. The easiest way of achieving this is running this script:
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User "<user name or alias>"
To learn more see the “Add a role to a role group” section of this TechNet article. - The location to which you will export the PST file must be a shared folder.
Syntax
Here is an example of a mailbox export request, which backs up an entire mailbox to a PST file:
New-MailboxExportRequest -Mailbox <user> -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst
Limiting the scope of exported contents is possible using additional parameters, e.g.:
-ContentFilter
Specifies what conditions the contents of a mailbox have to match to be exported into the PST file. The conditions are provided in the form of standard PowerShell logical clauses with several item properties available for filtering (wildcards are supported). Example of a script that exports items received prior to 2013-01-01 with subjects beginning with fwd:
New-MailboxExportRequest -Mailbox <user> -ContentFilter {(Received -lt '01/01/2013') -and (Subject -like 'fwd*')} -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst
-ExcludeFolders and -IncludeFolders
Just what it sounds like. You can choose from all Exchange mailbox folders. There are also two interesting features available:
- The capability to filter personal folders located under root folders using the <FolderName>/* syntax.
- The capability to filter well known Exchange mailbox folders regardless of their name in a local language using the #<FolderName>#/* syntax.
Here is an example of a script that exports only the Inbox and Sent Items folders:
New-MailboxExportRequest -IncludeFolders "#Inbox#/*","#SentItems#" -Mailbox <user> -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst
-IsArchive
A switch parameter, which defines the archive as the only source of the export. Example:
New-MailboxExportRequest -Mailbox <user> -IsArchive -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst
-Name
Sets the name of an export request. Useful for tracking or if you want to set more than 10 export requests per a single mailbox. This is because by default Exchange assigns only 10 consecutive names to export requests related to a single mailbox (starting with MailboxExport through MailboxExport9) and then stops. To proceed when all 10 default export request names have been taken, you have to either flush your export requests or start assigning your own names using the Name parameter. Example:
New-MailboxExportRequest -Name <unique name> -Mailbox <user> -IsArchive -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst
Additional information
A single MailboxExportRequest script can, of course, contain multiple parameters, including ones I didn’t mention. For a full list of available parameters, as well as syntax information and other details, consult the link below. TechNet: single mailbox exports to PST details
Bulk mailbox export to PST file
- The user performing the export must be a member of a role group which has the Mailbox Import Export role added (see previous section for more).
- The location to which you will export the PST file must be a shared folder.
Method 1
Save all mailboxes to a variable (in my case it’s AllMailboxes):
$AllMailboxes = Get-Mailbox
Export all mailboxes to PST files with names based on mailbox aliases (to use a different mailbox property replace the phrase “Alias” with its name):
$AllMailboxes|%{$_|New-MailboxExportRequest -FilePath \\<server FQDN>\<shared folder name>\$($_.Alias).pst}
Additional parameters can be used just as in single mailbox exports (see the first section of this article).
Method 2
Run the below script for the same effect as in Method 1 (the only difference is the use of the foreach command instead of piping):
foreach ($Mailbox in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $Mailbox -FilePath "\\<server FQDN>\<shared folder name>\$($Mailbox.Alias).pst" }
Limiting the scope of exported mailboxes
You will notice that the methods I describe result in exporting all mailboxes located on your servers. If you want to limit the scope of exported mailboxes, you can do so e.g. using the Get-Mailbox -Filter parameter. Here is an example of a script which lists mailboxes belonging to a security group called export1.
Get-Mailbox -Filter {MemberOfGroup -ne $export1}
NOTE: Using the -Filter parameter with the Get-Mailbox cmdlet results in excluding mailboxes that are defined in the parameter. This is why, to limit the scope of exported mailboxes to e.g. Batch1, you have to use the -Filterparameter to exclude all mailboxes that are not part of Batch1 – hence the use of the -ne (not equals) operator. Adding the -Filter parameter to the Get-Mailbox cmdlets in Method 1 and Method 2 scripts will result in limiting the scope of exported mailboxes. View the full list of filterable Get-Mailbox properties Get-Mailbox cmdlet explained
Mailbox backups to PST file: The bright and the dark side
All in all the drawbacks seem to outweigh the advantages, mainly due to clunky PST handling options and due to the files themselves being rather unstable:
Pros | Cons |
---|---|
|
|
Easy brick-level Exchange mailbox backups
You can have all the advantages of a PowerShell assisted mailbox-to-PST backup without its drawbacks. CodeTwo Backup for Exchange allows for secure granular mailbox backups to a stable and easily managed database. The software allows for scheduling multiple simultaneous backup and restore jobs, includes a smart versioning mechanism, full item search and preview, and additionally, allows for archiving storages to PST files as one of 2 available archiving models (learn more…).
Nguồn:
Comments
Post a Comment