Using Powershell to Import multiple PST files into Exchange 2007

e12icon[7]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.

System Requirements:

Mailbox Permissions

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 jdoe@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:

8 responses to “Using Powershell to Import multiple PST files into Exchange 2007”

  1. […] find out until after about an hour or two of cursing at the Exchange 2007 Powershell. This LINK and this LINK helped with the syntax, but it wasn’t until I found this GEM that I finally […]

  2. This is exactly what I was looking for. Thank you for sharing this great article. I am always looking for informative information like this. You are bookmarked! Have a good day.

  3. Kboven says:

    Hello

    Who will help us with importing multiple .pst files into our exchange server. Of course we will pay

    KLaasjan

  4. […] Using Powershell to Import multiple PST … – Hello. Who will help us with importing multiple .pst files into our exchange server. Of course we will pay. KLaasjan… […]

  5. […] Using Powershell to Import multiple PST files into Exchange 2007 – So if you ever need to mass import .pst files into Exchange 2007 here is the roadmap to … While this works for a single user by defining the location of the.pst file we will employ a different method to import multiple … After the import is complete Powershell will generate a .log and .xml … […]

  6. […] Using Powershell to Import multiple PST files into Exchange 2007 – Hello. Who will help us with importing multiple .pst files into our exchange server. Of course we will pay. KLaasjan […]

  7. […] Using Powershell to Import multiple PST files into Exchange 2007 – Hello. Who will help us with importing multiple .pst files into our exchange server. Of course we will pay. KLaasjan […]

Leave a Reply