Export Exchange mailbox data to PST with PowerShell (video guide)

Exporting mailboxes to PST is a well known workaround for backup, archiving and migration of Exchange mailboxes. The video below shows all the steps required to export emails, contacts, calendars and other mailbox items to a Personal Storage Table (PST) files.

Video’s transcription

Exporting mailboxes to PST is the native Exchange Server’s answer to the question of archiving and a manual migration to another server.

PST files are not very reliable, but they are still widely used. That’s why in this video I show how to export exchange mailbox data to PST.

You can export mailboxes within Outlook, using Exchange Admin Center or with PowerShell. Let’s skip the first two methods and see how to do this with PowerShell.

All cmdlets I use are listed below.

First, I assign the Mailbox Import Export role to my account.

Then, I run the New-MailboxExportRequest cmdlet to export this mailbox to this shared folder.

As a result, I will get a PST file with all items from the specified mailbox. Using additional attributes, I can limit the number of exported items. For example, I can export only the inbox folder, exclude items from the spam and deleted items folders, or export only items which are no older than a month.

Bulk export is just as easy. First, you have to get the list of mailboxes you want to export. You can use Get-Mailbox or Get-ADGroupMember to generate this list and push it to a variable. Then, paste the export script and point it to a shared folder location.

I get a PST file for each mailbox I listed.

Mind that you shouldn’t use PST files for migration or backup purposes if you have any other choice, as this method is severely flawed and prone to error. You can learn more on migration and backup with PST files by clicking this link.

Cmdlets used in the video

Assigning Mailbox Import Export role:
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User "<user name or alias>"

Exporting a single mailbox:
New-MailboxExportRequest -Mailbox <user> -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst

Exporting mailbox items older than a month and with a subject including a keyword:
New-MailboxExportRequest -Mailbox <user> -ContentFilter {Received -lt (get-date).adddays(-30)} -and (Subject -like 'fwd*')} -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst

Exporting all items except from Junk & Deleted Items:
New-MailboxExportRequest -ExcludeFolders "#JunkEmail#","#DeletedItems#" -Mailbox <user> -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst

Exporting only Archive:
New-MailboxExportRequest -Mailbox <user> -IsArchive -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst

Exporting all mailboxes to a specified shared folder:
$AllMailboxes = Get-Mailbox;
$AllMailboxes = $AllMailboxes.SamAccountName;
foreach ($Mailbox in $AllMailboxes) { New-MailboxExportRequest -name "export $Mailbox" -Mailbox $Mailbox -FilePath "\\<server FQDN>\<shared folder name>\$($Mailbox).pst"}

How to return your server’s FQDN and use it for exporting all mailboxes:
$myFQDN=(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain
foreach ($Mailbox in $AllMailboxes) { New-MailboxExportRequest -name "export-$Mailbox" -Mailbox $Mailbox -FilePath "\\$myFQDN\share\$($Mailbox.Alias).pst"}

Useful links:

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>