Using Powershell to Import multiple PST files into Exchange 2007
Most Exchange migrations that I am involved in are clients upgrading from an older version of Exchange but I’ve recently been engaged in implementing Microsoft Exchange 2007 at a client that previously used a linux mail system. This particular situation posed the additional challenge of all the mail being stored locally on the end users’ workstations in .pst files. Instead of manually importing the mail from the workstations I decided to leverage Powershell to ease the process.
From 10,000ft the method involves copying the .pst files to a file server, naming the .pst files according to their exchange alias (normally username), and then using Powershell on a 3rd server to import the mail files from the file server into the Exchange 2007 server. So if you ever need to mass import .pst files into Exchange 2007 here is the roadmap to success.
- 32-Bit Operating System
- Microsoft Exchange Server 2007 Management Tools 32-Bit (Download E2K7SP1EN32.exe)
- Update Rollup 8 for Exchange 2007 SP1 KB968012
- Outlook 2003 or Outlook 2007
- The account used for migration must be an Exchange Organization Admin or an Exchange Server Admin
After you install all the prerequisites and collected your .pst files it’s time to for some Powershell. We will be using the Import-Mailbox cmdlet but first we need to deal with mailbox permissions. In order to migrate mail into accounts that you don’t control we have to give ourselves full mailbox access.
The simple command for full access to a single mailbox is:
Add-MailboxPermission -Identity jdoe -User Administrator -AccessRights FullAccess
In this example we are granting the Administrator account full access to jdoe’s mailbox. However, we are dealing with multiple accounts so we will use:
Get-Mailbox | Add-MailboxPermission –user Administrator –AccessRight FullAccess –Inheritancetype all
This cmdlet uses a get-mailbox command to list all the mailboxes and then we pipe that command into a carte blanche cmdlet that grants the Administrator account full access to all listed mailboxes. Presto, permissions granted.
You’ve got mail (to import)
Next we use the import-mailbox cmdlet. Like all Powershell commands it is well documented so you can type “get-help import-mailbox –full” to see a full listing of options that include date filters, keywords, and exclude/include variables. To keep things simple here is the most basic command:
Import-Mailbox -Identity email@example.com -PSTFolderPath C:PSTFilesjdoe.pst
While this works for a single user by defining the location of the.pst file we will employ a different method to import multiple files. Here is the command to pull from a list of pst files:
Dir J:PST_Import*.pst | Import-Mailbox
In this example the “J:” drive is simply mapped to my File Server share and then we use *.pst to wildcard for all .pst files within the directory. (I took the additional step of sorting my .pst files by size and breaking them into different folders). Remember that you MUST name your .pst files as “exchangealias.pst” (i.e. jdoe.pst). This is how Powershell makes the association from the .pst to the user account. An easy way to check aliases is to enable the Exchange Alias column within your Active Directory Users and Computers column. If your users are segmented in to several different OUs you can do an query for all users. Select “Saved Queries”, right click and select New->Query. Name the Query “All Users” and click “Define Query”, in the users tab choose the “Name” drop down box and select “Has a value”, Click OK, and view the results. Now you can easily see all AD users and their Exchange Alias.
Once you issue the command you will be prompted with a confirmation dialog that prompts you to say Yes [Y], Yes to All [A], No [N], No to All [L], Suspend [S], and Help [?]. The default is Yes but I chose “Yes to All [A]” so I don’t have to individually confirm each import procedure. After the confirmation you should see the import run within a subroutine (background will be teal, text color yellow). It will display the mailbox name and give progress dialog that shows the different folders and the number of items being imported. After the import is complete Powershell will generate a .log and .xml report.
The process is straight forward and efficient. Thank you Powershell.
See these articles for more information:
- How to Import Mailbox Data – Microsoft TechNet Article BB691363
- How to Export and Import Mailboxes To and From PST – Microsoft SBS Blog
- How to Export and Import mailboxes to PST files in Exchange 2007 by the MS Exchange Team