The Open Code Project

Export Exchange Mailboxes to PST using Powershell

December 31st,2009 by Allan Bogh

Exporting mailboxes can be useful when an employee or user leaves the workplace. You may want to archive all of the files on a fileserver and delete the old mailbox. Here I will give you the commands and resources to export the mailbox to a PST and to know what to expect before you run into an error.

Environment Preparation

Exchange: Exchange doesn't have the PST exporting command built in until SP1, so you should upgrade Exchange to SP1 or higher.

Computer running the export command: This computer does not have to be the Exchange server, but it does need a few items. Make sure you have these tools installed before you begin:

  • Outlook 2003 SP2 or higher.
  • Exchange Management Console and Shell
  • Powershell 1.0 or higher
Take a look at this technet document from Microsoft for detailed instructions

Testing

It's best to run a few tests to see if you have the proper permissions on the mailboxes and if the system will allow you to export the mailbox. There are a few error messages that explain why you can't export, but they don't have the best descriptions. I will attempt to help with this.
Open the Exchange Management Shell

Run the following command:
Export-Mailbox –Identity <mailboxUser> -PSTFolderPath <pathToSavePST>
Example:
Export-Mailbox –Identity user.name -PSTFolderPath C:\Temp


You may get an error stating the following:

Error occurred in the step: Approving object. An unknown error has o
ccurred., error code: -2147221241


This means that the MAPI driver that is included in the client computer (one doing the export) might be bad and needs to be fixed. In the shell run this command:
 

fixmapi


Now, rerun the Export-Mailbox command.

Export-Mailbox –Identity user.name -PSTFolderPath C:\Temp


You may see a new error, this is most likely related to permissions.

Moving messages. Failed to copy messages to the destination mailbox store with error: MAPI or an unspecified service provider. ID no: 00000000-0000-00000000, error code: -1056749164

To get past this you can run this command:

Add-MailboxPermission -Identity user.name -User Admin01 -AccessRights FullAccess


Again, rerun your export command.

Export-Mailbox –Identity user.name -PSTFolderPath C:\Temp


You will notice the command working and a new file being created as "C:\Temp\user.name.pst".

Powershell

Now, to run this as a powershell script.

Create a new PS1 file (export-messages.ps1):

# this is the export-messages.ps1 file 
# to run it type: 
# powershell.exe export-messages.ps1 user.name C:\ExportFolder  
if($args.Length -eq 2){
    #This will produce errors when it's already been loaded, so the -ea fixes that
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ea SilentlyContinue
    #This will cause a yellow warning if the account is already in the DACL, just ignore it
    Add-MailboxPermission -Identity $args[0] -User $env:username -AccessRights FullAccess -Confirm:$false 
    Export-Mailbox –Identity $args[0] -PSTFolderPath $args[1] -Confirm:$false
}else{
    write-host "usage: powershell.exe export-messages.ps1 user.name ""C:\ExportFolder"""
}

Running it

To run it run this at the command prompt or from the Start - Run menu, type
powershell.exe exportmessages.ps1 user.name "C:\ExportFolder"

Comments (0)


:

:

:


: formatting help
Close

Formatting instructions:

You can use <a> tags but everything else will be stripped and your comment will look funny.

I swear, don't use html except the <a> tag or else some random star will supernova. Remember, we have a star right next to us, so don't try it.

This isn't bbcode either so don't use it. That is all.