Over this past summer, Wayfair upgraded from Exchange 2007 to a new, highly available, Exchange 2010 email environment.  With it brought many improvements, but with these enhancements came new methods for performing common tasks.  One operation affected by the upgrade was the mailbox export process.  To export a mailbox in Exchange 2007, one would simply grant the engineer or process performing this task administrative rights to the target mailbox and run the PowerShell command:

Export-Mailbox –Identity Username –PSTFolderPath \\Server\Destination

The procedure for exporting mailboxes in Exchange 2010 is a bit more complicated –

Role Assignment

In Exchange 2010, you must assign the “Mailbox Import Export” role to the user/service account that you would like to have the rights to export/import mailboxes.  First, you must grant access rights to the “Mailbox Import Export” role, and then set the task to run as the same user account.  To give this role assignment, open up the Exchange Management Shell and run the following command”

New-ManagementRoleAssignment –Role “Mailbox Import Export” -User username@domain.com

Now the user account you specified above has the rights execute mailbox Import and Export.  As a side note, as with all things at Wayfair, we want to automate these types of processes so the mailbox export is set to run as a scheduled task.

SAN/Remote Server Permissions

Unlike 2007, Exchange 2010 requires you to export mailboxes to a UNC path; you can no longer export mailbox data a local drive.  The destination UNC path must have the correct access rights set:

  1. Give the user account you granted the “Mailbox Import Export” role full control for Share Permissions as well as full control of the NTFS permissions.
  2. Give the built-in user account “Exchange Trusted Subsystem” full control for Share Permissions as well as full control of the NTFS permissions.

Now the user account you created will have the ability to successfully export or import from the share path you designated.

Exporting Mailboxes

Now that the roles and permissions are all set, we can get to the main course of why we’re here: exporting mailboxes!

Before we get into the process, there are a few important things to note.  A big problem we ran into was recurring Watson errors during export attempts or an error along the lines of Operation is not valid due to the current state of the object.  We discovered that this issue was not present when running the mailbox export request on the Client Access Server (CAS).  We discovered that, when importing the Exchange 2010 snap-in into our PowerShell session, it wasn’t properly connecting to the CAS remotely. To get around this, you must connect to the CAS with the following command:

. “$env:ExchangeInstallPath\bin\RemoteExchange.ps1”; Connect-ExchangeServer -Auto –AllowClobber –ClearCache

This command “.” sources the RemoteExchange.ps1 file from the path to which Exchange is installed.  This is the same file that the Exchange Management Shell uses.  The Connect-ExchangeServer command connects to the CAS, the Auto switch will automatically select the server to connect to, the AllowClobber switch basically replaces any commands that already exist with those from the server, and the ClearCache switch clears any data that may be left in cache.

Now that we’ve got that little nugget of truth out of the way, let’s move onto the actual export.  You can use the following command to export the mailbox.

New-MailboxExportRequest -Mailbox username -FilePath \\Server\Destination\username.pst -Priority:High -BadItemLimit:3 -Confirm:$false -Name:username –Verbose

Obviously you can play around with the switches to your liking but that’s the only command you need to run to export a mailbox.  The really cool thing is that the export will take place on the CAS server rather than the machine you’re running it on, so it won’t add any additional load to the machine you kick the export off from. Of course, be mindful of potential periods of high load on your particular CAS environment.

Checking Export Status

Now that we’ve started the export process, we want to see how it’s coming along.  Here are a few commands you can use to check out status:

  • Get-MailboxExportRequest
  • Get-MailboxExportRequestStatistics
  • Get-MailboxExportRequest | Get-MailboxExportRequestStatistics
  • Get-MailboxExportRequest | Where-Object { $_.Status –eq “Completed” }

Once an export is completed and you run Get-MailboxExportRequest you’ll see results similar to this:

Name                      Mailbox                                      Status
Username              domain.com/domainou…         Completed

Once a mailbox export request completes, it stays there until you remove the export request.  This command will remove any export requests with a status of Completed.

  • Get-MailboxExportRequest | Where-Object { $_.Status -eq “Completed” } | Remove-MailboxExportRequest

That’s all there is to it.  The initial set up is a bit tricky compared to Exchange 2007, but once you’ve got that all done, you’re ready to start exporting mailboxes left and right from Exchange 2010!

Please check out the example script at the Wayfair GitHub respository, found here – https://github.com/wayfair/exchange-mailbox-export