Exporting Exchange mailboxes in chunks with Powershell

Today’s post is about chunking email exports from Exchange 2007 with Powershell.

Back in the days of Exchange 5.5 through 2003, exporting a mailbox was done with ExMerge. Exchange admins had a love/hate relationship with ExMerge. It wasn’t the prettiest GUI around, but it got the job done.

Then along came Exchange 2007, and Microsoft decided that GUIs were overrated. So they gave us this wonderful thing called the Exchange Admin Console, using Powershell. Now you could export a mailbox with a single, non-intuitive command line.

Unfortunately, one of the side effects of ExMerge that went away was the ability to split PST files. Since ExMerge only supported ANSI PST format, it was limited to 2GB per file. As mailboxes had already started to grow and Exchange supported mailboxes much larger than 2 GB, ExMerge would automatically split a mailbox into multiple PST files. Now that the Export-Mailbox commandlet supports UNICODE PSTs, Microsoft apparently decided there was no longer a reason to split PST files.

But as I said, mailboxes have gotten MUCH larger. And journal mailboxes can be downright HUGE. So how can you export a 100GB journal mailbox without blowing up the export or creating a PST too large to open?

Export-Mailbox does support date filtering, but manually chunking a mailbox can take a very long time. Below is a Powershell script I wrote to export a mailbox, one month at a time. The only values that need to be changed are the mailbox name, targetlocation, and finish date. The script will start with the most current and work backward, creating export PSTs with one month of data at a time.

$TargetUserName = “username”

$Location = “C:\Temp\”

$finish = Get-Date -Date “1/1/2009”

$startdate = Get-Date

$startofmonth = Get-Date $startdate -day 1 -hour 0 -minute 0 -second 0

$endofmonth = (($startofmonth).AddMonths(1).AddSeconds(-1))

do {

$startvalue = Get-Date -format d -Date $startofmonth

$endvalue = Get-Date -format d -Date $endofmonth

Export-Mailbox -identity $TargetUserName -StartDate $startvalue -EndDate $endvalue -PSTFolderPath $Location -Confirm:$false

$Monthname = $Startofmonth.Month

$Yearname = $startofmonth.Year

Rename-Item $Location$TargetUserName”.PST” $Location$TargetUserName”-“$Monthname$Yearname”.PST”

$startofmonth = (($startofmonth).AddMonths(-1))

$endofmonth = (($startofmonth).AddMonths(1).AddSeconds(-1))

}

while ($startofmonth -ge $finish)

 

Voila! You now have a set of chunked PST files that should be much more manageable than a single 100 GB file.

Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s