PowerShell Commands to export Exchange 2010 mailbox to PST

In Exchange 2010 we have the facility to export to PST directly from the Exchange server without further interventions unlike its predecessor where in Exchange 2007 you needed to setup another computer with a 32 bit Office installation. Also we don’t need the burden of the ExMerge as with Exchange 2010 it introduced the New-MailboxExportRequest PowerShell cmdlet that we can use to export the PST files at our pleasure.

Unfortunately, for us there is no functionality in the GUI of the Exchange Management and command line is your only choice to export to PST a mailbox or a set of mailboxes. First things first, although you have Exchange 2010 this does not make you able to export mailboxes using the command. For this to work you must have your Exchange 2010 running SP1 or later.

We need to check if the username you are exporting the PST files with, has the right permissions. On the folder you must have the username you are exporting with as full control along with the Exchange Trusted Subsystem.

Open the Exchange Management Shell and type the below to give your user the right permissions.

New-ManagementRoleAssignment –Role “Mailbox Import Export” –User “YourUsername”

To export mailboxes, you cannot use a direct drive like D:\PSTFiles, you will need to have a share. For the share you will need to give full permissions to the user you are exporting with. An example would be \\srv01\d$\PstFiles.

After this we can now start exporting the mailboxes.

The simple command to export the whole mailbox of a user is below

New-MailboxExportRequest –Mailbox “SourceMailbox” –FilePath “Destination”

This will star the export process of the mailbox. If you have an archive mailbox to export you will need to add the –IsArchive at the end.

If you have some old mailboxes which were disconnected, the command remains the same but you cannot directly export a disconnected mailbox. You would need to create a new user in your Active Directory and then you would need to connect the disconnected mailbox to that user. After this you can use the New-MailboxExportRequest.

Exporting a mailbox has some extra options like the IncludeFolder, ExlcudeFolder and export time period. These can come in handy when you are exporting by year or preparing to export a mailbox for Office 365 migration and you don’t want to export the Deleted Items or the SPAM folder for example or you will only need to export the Inbox folder. Here are some examples on how to export the mailboxes with these options.

New-MailboxExportRequest –Mailbox JamesSmith –FilePath \\srv01\d$\PSTFiles\JamesSmith.pst -IncludeFolder “#Inbox#”

The above command will export the mailbox of JamesSmith but will only export the folder Inbox.

New-MailboxExportRequest –Mailbox JamesSmith –FilePath \\srv01\d$\PSTFiles\JamesSmith.pst -ExcludeFolder “#DeletedItems#”

The above will export the whole mailbox of James Smith but will exclude the folder called DeletedItems. If you have wanted to export the whole mailbox apart from more than one folder you would need to add multiple folders using the comma as a separator. This part is also applicable to both include and exclude. An example is below.

New-MailboxExportRequest –Mailbox JamesSmith –FilePath \\srv01\d$\PSTFiles\JamesSmith.pst -ExcludeFolder “#DeletedItems#”, “#Spam#”

Another option as said is the export by date range. This comes with command of lt which means less than and gt which means greater than. If you wish to export all the mailbox of a user till 2017 you would need to set the command as below.

New-MailboxExportRequest –Mailbox JamesSmith –FilePath \\srv01\d$\PSTFiles\JamesSmith.pst -Content Filter {(Received –lt ‘01/01/2018’)}

If you wish to export all the mailbox of a user from 2017 onwards, you would need to set the command as below.

New-MailboxExportRequest –Mailbox JamesSmith –FilePath \\srv01\d$\PSTFiles\JamesSmith.pst -Content Filter {(Received –gt ‘01/01/2018’)}

If you wish to export all the mailbox of a user from 2016 till 2017 only, you would need to set the command as below.

New-MailboxExportRequest –Mailbox JamesSmith –FilePath \\srv01\d$\PSTFiles\JamesSmith.pst -Content Filter {(Received –gt ‘12/31/2015’) (Received –lt ‘01/01/2018’)}

To view the status of the export one can use the Get-MailboxExportRequest cmdlet.

Thou this is not so informative at least you will know if it complete, in progress or failed. To get just a little bit of information on the mailbox you are exporting you can use the below command where the name is the name of the mailbox export job you are executing. This can be found by looking at the Get-MailboxExportRequest results.

Get-MailboxExportRequest –Name MailboxExport | fl

There is a way also to get the percentage of the whole export for a particular mailbox. The command is the Get-MailboxExportRequestStatistics and it will give you where the mailbox is right at that moment.

Get-MaibloxExportRequest | Get-MailboxExporRequestStatistics

When exporting a lot of mailboxes you will notice that the completed and failed are not automatically cleared from the list and you would need to do this through PowerShell by typing the following command for each status.

Get-MailboxExportRequest | where {$status –eq “Completed”} | Remove- MailboxExportRequest

Of course to clear the ones that are marked as failed you would need to change the status on the command from Completed to Failed.

On top of this there are some disadvantages, which are human error as it’s easy to make a mistake especially when making various folder exclusions and date ranges. The fact that you can only export using the PowerShell command line and the margin of error is big. Alternatively, Stellar Converter for EDB can export mailboxes with no issues and that the administration effort was minimal. Apart from that, the application is a great tool to import directly from an EDB file to Office 365.



Photo by Charlize Birdsinger on Unsplash

Leave a Reply

Your email address will not be published. Required fields are marked *