Have you ever come up with the situation to export your Exchange mailboxes to PST files? From time to time, an Exchange administrator needs to export some or all of his organization’s mailboxes out of the exchange database.
In previous versions of exchange sever a tool called ExMerge.exe was able to assist in such cases. In the 2007 version of Exchange server this tool has been replaced by the export-mailbox cmdlet. The export-mailbox cmdlet can be used to export or move the contents of a mailbox, between mailboxes or to a PST file (SP1+). Although export-mailbox is an Exchange server 2007 tool, the source and target mailboxes can be on one of the following:

  • Exchange 2007 server
  • Exchange Server 2003 SP2 or later
  • Exchange Server 2000 SP3 or later

To export data to a .pst file, you must execute the export-mailbox cmdlet from a 32-bit computer that has the 32-bit version of Exchange management tools installed, along with MS Outlook 2003 SP2+ or MS Outlook 2007. Note that export-mailbox cmdlet cannot export data between mailboxes in different forests.
Since export-mailbox is a powershell cmdlet, the output of other cmdlets like get-recipient or get-mailbox can be piped into the tool to streamline functionality. The export-mailbox cmdlet can filter against:

  • Subject Keywords (-SubjectKeywords)
  • Content keywords (-ContentKeywords)
  • Keywords found in subject, body or attachments (-AllContentKeywords)
  • Filenames of attachments. You can also include wildcard characters like *.pdf or Article*.txt (-AttachmentFilenames)
  • Sender and/or recipient keywords (-SenderKeywords & -RecipientKeywords)
  • Specified timeframe (–StartDate & –EndDate)
  • Messages locale (-Locale)
  • Included or excluded mailbox folders (-IncludeFolders & -ExcludeFolders)

Also, you can choose if you want to just export the contents of a mailbox or move them and delete the exported data from the source (-DeleteContent).

A very common example is an organizational policy which dictates that all employee mailboxes should be exported in an annual basis to offline media for archiving purposes. In order to achieve that goal an exchange administrator should be able to move organizational mailbox data from source mailboxes to PST files using a date filter:

Get-mailbox export-mailbox -EndDate “01/01/2007” -ExcludeFolders “\Contacts”,”\Journal”,” \Junk E-Mail”,”\Deleted Items”,”\Calendar”,”\Sync Issues”,”\Drafts”,”\Notes”,”\Tasks”,”\Outbox” -PstFolderPath c:\MyPSTs -DeleteContent -confirm:$false

If we analyze the above command:

  • The Get-Mailbox command returns all mailboxes in the organization
  • The Export-Mailbox cmdlet gets its input from the get-mailbox command
  • The EndDate switch filters out all items after 01/01/2007
  • The ExcludeFolder switch excludes all folders we don’t want to include in our archiving procedure, such as Tasks and Contacts
  • The PstFolderPath switch directs the PST files folder location to c:\MyPSTs
  • The DeleteContent switch deletes exported items from source mailboxes
  • The Confirm:$False global switch disables the confirmation dialog during the mailbox export procedure

The above command can be used with variations in order to include more advance filters like exporting mailboxes with specific subject keywords from a single organizational unit:

Get-Mailbox –OrganizationalUnit “ou=Accounting,ou=Structure,dc=mydomain,dc=local” export-mailbox –SubjectKeywords “Payroll” –PstFolderPath c:\MyPSTs –DeleteContent –confirm:$false

Note that under the –PstFolderPath location multiple files will be created, in the form of accountname.pst, for each respective user defined by the export command.