Mar 02

How to: Export all your organization’s Exchange Mailboxes to .pst files

How to: Export all your organization’s Exchange Mailboxes to .pst files

Sometimes for backup, migration or disaster recovery purposes it is necessary to export your Exchange’s mailboxes. Although through time the method has changed and at a point in time it required Outlook to be installed on your server, life is better now. Exchange Server 2010 Service Pack 1 introduced a new method for exporting mailboxes called which replaces the previous Export-Mailbox command that required Outlook and generally speaking was a pain.

As a prerequisite for the export you will need to be assigned a special role that allows you to import or export mailboxes. Not only do you need that right, but it will enable the use of the mailbox request commands. Furthermore, those requests are handled by the Client Access Server role (CAS). I imagine as any CAS server on your organization can handle the request you are asked to provide a UNC path not a local folder with special rights, that way any server should be able to access it.

Step 1: Give yourself access to import and export mailboxes

This is fairly straightforward, simply run the following command on your Exchange Management Shell:

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

Be sure to replace DomainUserName with the right values for your user and organization.

In case you want to give a security group the permission rather than an individual/user, you can accomplish that with the following command line:

New-ManagementRoleAssignment -Role “Mailbox Import Export” -SecurityGroup Administrators

Step 2: Create a UNC path were to place the .pst exports

If you are lazy, simply use one of those admin paths like C$ or an existing one you have, if not go ahead and create a shared folder on a server that will be dedicated to this task. The one thing you can’t get away from is giving that folder the correct access rights so that Exchange can write to it. All that is required here is that the network share gives the Exchange Trusted Subsystem group read/write permission to it.

Step 3: Submit the export requests

This is again very simple if all you are doing is exporting a user’s mailbox. Things get a bit spiced up once you decide you have many users and you are not in the mood to type each of their names, etc. But before we get ahead of ourselves here is the syntax in order to perform the basic export requests:

EXAMPLE 1


This example exports the user Ayla Kol’s primary mailbox to a .pst file on the network shared folder PSTFileShare on SERVER01.

New-MailboxExportRequest -Mailbox AylaKol -FilePath "SERVER01PSTFileShareAyla_Recovered.pst"

EXAMPLE 2


This example exports the user Kweku’s archive to a .pst file on the network shared folder PSTFileShare on SERVER01.

New-MailboxExportRequest -Mailbox Kweku -FilePath "SERVER01PSTFileShareKweku_Archive.pst" -IsArchive

EXAMPLE 3


This example exports messages that contain the words “company” and “profit” in the body of the message for the user Tony received before January 1, 2012.

New-MailboxExportRequest -Mailbox Tony -ContentFilter {(body -like "*company*") -and (body -like "*profit*") -and (Received -lt "01/01/2012")} -FilePath "SERVER01PSTFileShareTony_CompanyProfits.pst"

EXAMPLE 4


This example exports all messages from Kweku’s Inbox to the .pst file InPlaceHold.

New-MailboxExportRequest -Mailbox Kweku -IncludeFolders "#Inbox#" -FilePath SERVER01PSTFileShareKwekuInPlaceHold.pst

 The examples come from TechNet, so I am assuming these are the most common scenarios out there people would use the Mailbox export request for. Now, in my case I want to export all my users mailboxes as part of a backup and restore operation. I am incredibly lazy and typing the same command more than once already begins to cause me issues, so spend more time digging on the Internet and here is what I came up with:

First: Determine the users you wish to export

Export all mailboxes from a designated mailbox database:
Get-Mailbox –Database “Mailbox Database I” -ResultSize Unlimited

Export all mailboxes from a designated server:
Get-Mailbox -Server Exchange2010 -ResultSize Unlimited

Export all mailboxes from the entire Exchange organization (from all servers and all databases)
Get-Mailbox -ResultSize Unlimited

Export all mailboxes for users in a specific AD Organizational Unit
Get-Mailbox -OrganizationalUnit Partners -ResultSize Unlimited

Second: Use that dataset/query to feed into a script to export

The following script will use the results from any of the commands mentioned above in order to generate all the required Mailbox export requests that you need. I would suggest first running the selection command to see if that is the subset of users you are looking for and then creating the actual export requests. As you would suspect, depending on the number of users, size of their mailboxes and specs of your server this could take a pretty long time.

$mailboxes = YOUR DATASET

Foreach ($mailbox in $mailboxes) {

New-MailboxExportRequest -Mailbox $mailbox -FilePath serverPSTExports$mailbox.pst

}

So based on that, below is an example of how to export all the mailboxes from a particular Exchange server in your organization:

$mailboxes = Get-Mailbox -Server Exchange2010 -ResultSize Unlimited

Foreach ($mailbox in $mailboxes) {

New-MailboxExportRequest -Mailbox $mailbox -FilePath serverPSTExports$mailbox.pst

}

The beauty of this is that you can type that on your Exchange Management Shell powered by PowerShell. No need to create a script file, just copy paste into it and enjoy PowerShell doing all the heavy lifting for you!

Step 4: Monitor your requests and clean your server

So, you obviously want to know how’s your request doing, how far has it progressed and which mailboxes have already been exported. Another fun thing to keep in mind is that your request will remain on the server in definitively. Thing of it as a print queue that does not delete the jobs that have already printed. I don’t think you will have any issues leaving them there but if later on you do more requests that list can get big and the information there could very well be obsolete for you and your organization. I will cover how to clean up the list of requests once the requests are completed and you don’t want that information there any more.

First, how to monitor the progress. Simply run the following command on your Exchange Management Shell to obtain all the requests and obtain their details:

Get-MailboxExportRequest | Get-MailboxExportRequestStatistics

I’ve also seen the following command which results in only the completed requests being displayed:

C:>Get-MailboxExportRequest | where {$_.status -eq “Completed”}

although I personally prefer the first one as I get statistic even though that might take longer to output. And finally for when you are ready to remove the completed requests:

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

and that’s it!

Oh, and you can also export email archives using this guide. All you have to do is include the -IsArchive parameter on the New-ExportMailboxRequest command like so:

New-MailboxExportRequest -Mailbox Bill.Gates -FilePath SecretMSserverpstBill.Gates.pst -IsArchive

Enhanced by Zemanta

Leave a Reply

%d bloggers like this: