So today I was asked to delete a bunch of email accounts off of Exchange that were tied to users that are no longer with the company. Due to the security requirements we follow where I work, we have to maintain a list of users that previously worked for the company. We maintain them in a Disabled User OU in AD to easily ID said users. However we are not required to maintain email for nearly as long, so we were asked to make a backup of the mailbox’s to PST files, just in case, and put them on a drive and into a vault prior to removal of the emails. In this 1st run after the policy was created we found we had a bunch of mailboxes to export so we came up with a simple one liner to do this for us.
To that end we used Powershell to export the users in the “Disabled OU” in AD and find any mailboxes associated with those users and export them.
The requirements to make this work under Exchange 2007 are a bit of a pain if you are running Windows 7 64bit those requirements are listed below.
A Windows 7 32bit machine
Exchange tools (sp1) installed on the local machine
Outlook 32bit installed
Once you have that you can actually run the Exchange Powershell script I used:
[PS] C:\>Get-Mailbox -OrganizationalUnit "domain/Disabled User OU" | add-mailboxpermission -accessrights fullaccess -user ADAdminAccount -confirm:$false | Export-Mailbox -PSTFolderPath "C:\Path\"
So this script, goes in and retrieves a list of mailboxes in a given OU, grants the user running the script “ADAdminAccount” permission to export the mail, and then exports it to a local drive with one pst file per user in the OU in question. Very handy.