A feature of Exchange 2010 SP1 was to store “older” emails in a different database and to have that database on a cheaper storage subsystem. Given that Exchage primary mailboxes work very well on slower storage anyway you could well be in the position of needing to move archived content, that is content moved to the archive via a retention policy, back to the primary mailbox.
To do this you need to make use of the Export-Mailbox and Import-Mailbox cmdlets to export the contents of the archive to a PST file and them import the PST file back into the primary mailbox.
This process is broken into two parts. The preparation of the server to do the Export/Import processes and then the cmdlets to move the users.
Preparing the Environment
The account needed to run the Export-Mailbox and Import-Mailbox commands needs to be granted the “Mailbox Import Export” role assignment and you need to create a file share on one of your CAS servers that the Exchange Trusted Subsystem has permission to.
To create the File Share create a folder on one CAS server and share it with Advanced sharing. Ensure that “Exchange Trusted Subsystem” has read and write permissions on the file system and Everyone has full control to the share:
If you give your account modify permissions as well, then you will be able to delete the PST file that gets created at the end of this process when it is no longer needed.
Modify your Exchange account so that you have the Mailbox Import Export” role assignment
New-ManagementRoleAssignment –Role “Mailbox Import Export” –User AD\Administrator
You will need to close and re-open any Exchange Management Shell windows you have open to pick up these permission changes. Then you are ready to begin the process of merging the archive out to PST and then the PST into the primary mailbox.
Merging Archives Back to Primary Mailboxes
This process in brief is to ensure Retention Hold is enabled for the mailbox in question and then to run the cmdlets to do the export followed by the import.
These can all be done from the Exchange Management Shell using the following cmdlets. This will prompt for the username and then turn off Retention Hold, export the mailbox (you will need to change the share to match your environment) and then import the mailbox.
The steps to export the mailbox are as follows:
- $UserToMerge = Read-Host -Prompt “Username of user to merge archive back to primary mailbox?”
- New-MailboxExportRequest -Mailbox $UserToMerge -FilePath “\\CAS-SERVER\ExportImport\$UserToMerge.pst” -IsArchive $True
- Get-MailboxStatistics $UserToMerge -Archive | ft DisplayName,TotalItemSize
The above steps will prompt for the username and then start the export of this users archive folder to the given file share. Exports will take time, and this is dependant upon the size of the archive. Therefore this script will finish with an output of the size of the archive (Get-MailboxStatistics –Archive) and the current status of the export. You can repeat the last command on a regular basis to see when the export is complete or use the following to see the percentage complete status:
Once the export is complete the export request can be removed:
You now have a PST file that is a copy of the data found in the users archive. To import this data back into the primary mailbox you need to run the following command:
- New-MailboxImportRequest –Mailbox $UserToMerge -FilePath \\CAS-SERVER\ExportImport\$UserToMerge.pst
- Get-MailboxImportRequest | Get-MailboxImportRequestStatistics
As with the export, the last line allows for you to view the current status of the import.
Once the import is finished the following command will clean up the import requests:
And don’t forget to delete the PST files and remove the archive for the user as well – as the PST is extra to requirements now, and the archive contains content that is replicated to the primary mailbox. If you ever turn the archive back on again then you need to have a new archive rather than using the old one.
To remove a users archive and delete the PST (remembering to change the path shown here) run the following:
- Disable-Mailbox $UserToMerge -Archive -Confirm:$false
- Del \\CAS-SERVER\ExportImport\$UserToMerge.pst
Finally, its possible to save all these commands to two PS1 files (one for the export commands and one for the import ones) to make the repeating of this for other users easier. Or, take a look at Steve Goodman’s blog on Exporting Mailboxes to assist you in writing a script to do this process in bulk.
Can you expand more on the “Disable-Mailbox -Archive” action?
1. Specifically, is it wise to disable the archive BEFORE importing so we don’t have a sieve situation (adding emails slowly, but emails just re-archive themselves)?
2. Does “Disable-Mailbox -Archive” actually DELETE the Archive and DELETE the email in the Archive?
In Exchange “disable” typically stops the object existing but leaves the AD object, “remove” does the same as disable and removes the AD object.
So in this case “Disable-Mailbox -Archive” removes the archive from the user. In Exchange 2010/2013 on-premises this creates a orphaned mailbox object that is typically removed 30 days later and can be reattached. In Office 365 this mailbox data will remain around forever if your user is on litigation hold. If it is not, then the archive mailbox is gone and cannot be reattached.
You need to export the mailbox to the PST file before you disable the archive.
Tt seems some of the longer commands are truncated. Any chance to get this fixed on this page?
this work great!
there is a way to do some “wait” between the export and the import ?
to write only script one with the export and import ….
The import can only start once the export is complete. As the post says, this will take different amounts of time based on the size of the exported archive. Therefore it is a two step process, unless you want to run a loop in the script looking for the completed status and then move on, but that is inefficient!
Thanks for a great tutorial!
I have followed your guidelines, but it fails with an ManagementObjectNotFoundException.
Also, I do not get any confirmation at step 2. Just the prompt.
The blog has lots of sections, and therefore there are a few “Step 2” bits! Can you let me know where you are having the issue please?