Archive Mailboxes to .PST 's.

  • Archive terminated employees mailboxes on-demand
  • Archive system account mailboxes on a regular schedule

We have a number of compliance obligations at the grind.  We need to retain any contact information and customer correspondence that a former employee maintains in their e-mail. We also have service account mailboxes that collect notifications and grow large over time.

In both cases it's beneficial for us to siphon off the contents of the mailboxes to a flat file (.pst) - either on-demand or using a Scheduled Task.

I've compiled a few scripts that work both to be called from a web application and as a Scheduled Task.  The web application performs on-demand archival while the Scheduled Task dutifully siphons out the contents of those large service account mailboxes on a predictable schedule.

One disclaimer:  I've found the on-demand application of these scripts to be hit-and-miss.  So I use the on-demand web application to simply schedule a task that calls the mailbox archival scripts at a point in the not-so-distant-future.  This has proven to be way more reliable.

We'll start things off with a .bat file.  This script gets the current time, so you're sure that the .pst file you're generating has a unique name.  This ensures if you re-run the script you're not overwriting the contents of any existing .pst files. You'll call the PowerShell script with two arguments: 1. The name of the mailbox *alias* 2. The UNC path and file name (complete with .pst extension) of the .pst file you want to create. Example: You'd call this .bat like so: mailboxarchive.bat ryanb \\\archivedfiles\ryanb\

Here's the contents of the consolefile, exshell.psc1 (nothing earth-shattering here):

Here's a script to *archive* the mailbox. Note that:

1. The mailbox will remain enabled.

2. The "ServiceAccount" is a domain account that exists and that has full rights to the mailbox:

3. You're calling this script with the name of the mailbox *alias*

Here's a script to *archive and disable* the mailbox. Same rules regarding parameters apply:

If you decide to call this script from a web application that your team uses for on-demand termination of employee accounts. Here's what I use for creating a Scheduled Task. It's in C, so just throw it in your favorite compiler: }