Exchange 2010 SP1 PST Export via Command Line (Powershell)

With the new features that came out in SP1 for Exchange 2010 there finally is access directly on the server to export mailboxes into PSTs from the Exchange Server itself without the need for Office or ExMerge.

I wrote a simple batch-job that will run the entire export into a local (or network) directory.

I based parts of this on the following (dutch) article:

First you must run the command to allow access to the command, without these permissions the commands are not even visible.

New-ManagementRoleAssignment -Role “Mailbox Import Export” -User AdminExchange
New-ManagementRoleAssignment -Role “Mailbox Import Export” -SecurityGroup “UG Exchange Backup Operators”

I prefer to use the second one as it is beter practice to use groups instead of assigning permissions directly to accounts. After you have done this make sure your account has the correct permissions applied to the (gpresult /r), it may require logging out and in. You should now see the commands in the EMC.

Next step is to make the actual batchjob (if you need this). I’ve simply opened the path on the Short-cut for the EMC;

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command “. ‘D:\Exchange\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto”

Using the EMC you can figure out all the triggers for the New-MailboxExportRequest, what I will outline here is a simple script that simply grabs all mailboxes from the environment and then exports them.

The above commandline is tweaked to the following;

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command “. ‘D:\Exchange\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; $Users = Get-Mailbox; $Users | ForEach {New-MailboxExportRequest -Mailbox $_ -FilePath \\Localhost\D$\Backup\$_.pst}

Firstly notice that I took out the -noexit part, as we want the Powershell to close itself once it’s done. Secondly, note that the -FilePath requires a UNC so if you wish to backup to the local server please use the method I used above, otherwise use a FQDN.

After the automated connection the the Exchange Server I added two seperate lines of code which I will explain:

$Users = Get-Mailbox;

This simply populates the User variable with the results from Get-Mailbox, if you want to make a more specific selection you should do so here.

$Users | ForEach {New-MailboxExportRequest -Mailbox $_ -FilePath \\Localhost\D$\Backup\$_.pst}

Here we take each single mailbox we encounter and fire a New-MailboxExportRequest to the server. The $_ is the users Name in this case which I use twice in the command. Once to access the correct mailbox and once to provide the name for the PST.

Depending on your environment and server exporting to PST may cause significant load on the Exchange Server.

Leave a Reply

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