Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bulk Import & Export of Mailboxes to/from PST

PowerShell

Bulk Import & Export of Mailboxes to/from PST

by  markdmac  Posted    (Edited  )
Before you begin trying to export or import PST files you need to assign a specific right to do so. Even if you are already an Exchange admin, you still need to do this step.

Prepare Your Account
Using the Exchange Management Shell execute the following code:
Code:
New-ManagementRoleAssignment -Role "Mailbox Import export" -User Login.Name

After the command completes you must close and re-open the Shell for the right to actually be assigned.

Export Mailboxes
You are now ready to export users mailboxes to PST. First create a list of the accounts to be exported. Use notepad and put each login name on one line. Name the file ExportSource.txt.

Create a script to do the actual export. Below is the simple code needed to do this (name the file ExportFromList.ps1. Be sure to change the parts in [red]red[/red]. Note that the destination MUST be a UNC path. I prefer to use an external hard drive I can quickly move to my destination server. THis prevents extra traffic on the network.
Code:
Get-Content [red]C:\Temp\PST[/red]\ExportSource.txt | % {
New-MailboxExportRequest -Mailbox $_ -FilePath "[red]\\server\share[/red]\$_.pst"
}

To Check status of exports run the following command:

Code:
Get-MailboxExportRequest | Select Status,Mailbox | Export-CSV C:\Temp\EXportStatus.csv -nti;notepad c:\Temp\ExportStatus.csv

If the exports fail there is likely corruption in the database.
You can allow the export to continue by altering the number of bad items.

To allow up to 50 bad items, add a -BadItemLimit. To increase the number of bad items higher than 50, you must also add -AcceptLargeDataLoss after the number of bad items. An example with both parameters added is below.

Code:
Get-Content C:\Temp\PST\ExportSource.txt | % {
New-MailboxExportRequest -Mailbox $_ -BadItemLimit 150 -AcceptLargeDataLoss -FilePath "\\Server\Share\$_.pst"
}

Import PSTs to Mailboxes

To import your newly exported PST file you just need to have them stored in a directory you can access via UNC path. Create a text file and put the following code in it. Edit the UNC path in the script and execute via PowerShell. Note that if you exported and are importing between different Exchange environments (migration) you must prepare your account as specified above.

Code:
Dir \\[red]server\share[/red]\*.pst | %{
	New-MailboxImportRequest -Mailbox $_.BaseName -Filepath $_.FullName -ConflictResolutionOption KeepLatestItem 
}

Happy Scripting.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top