Email users save old email messages for several reasons: to keep meticulous communications records, for legal reasons, or to comply with corporate policy. Outlook uses Personal Folders (.pst) files to archive email messages. Problems can arise when users save numerous email messages. Archives sometimes grow so large that they corrupt the .pst file and make it useless. In addition, archives stored on network file servers can waste valuable disk space.

Although users rarely need to access email messages that are more than a year old, if they do, having an offline archive is useful. An offline archive is an archive stored on DLT, CD-ROM, or DVD. You can bring the archive online when you need to access data in the archive's time period. A problem with offline archiving is that some users are technically challenged and use one archive for everything rather than creating a separate archive for a specific time period. Another problem is that you need read and write permissions on a Personal Folder to open it. You can't open a Personal Folder from CD-ROM or DVD because the folder will be read-only.

Sometimes systems administrators must clean up archives stored on the network or intervene to prevent significantly large archives from becoming corrupted. Such tasks present problems because you can't just take away an archive from a user—especially if the user works from both the mailbox and archive. An ideal solution is to split the archive in such a way as to leave the user with only the most recent messages while storing the older messages in a separate archive for offline storage.

The script that Web Listing 1 shows uses Outlook's application object to split an archive. PSTSplitter.vbs creates a new archive file with the name you specify or an automatically generated name based on the script's parameters. Then, the script duplicates the entire folder structure from your archive so that messages stay in the same-named folder you originally stored them in. Finally, the script moves files from the old archive to the new archive based on the date range you specify. You need to use CScript.exe to run PSTSplitter.vbs because the script outputs its progress to the console window as it runs. One of the script's limitations is that it can process only archives that contain mail messages. Archived calendars, tasks, or journals, for example, don't transfer and might cause an error. The script also can't process .pst files that contain spaces in the path because of the fileExists method's limitations.

Outlook 2000 and later versions' AddStore and RemoveStore methods make PSTSplitter.vbs possible. You must run the script on a computer running Outlook 2000 or later. The computer must have an Outlook profile for an Exchange Server mailbox already created and set as the default Information Store (IS). The computer must not have any MSN Hotmail or IMAP accounts because the RemoveStore method can't remove these accounts. You'll also need access to the .pst file you're going to process, although the Outlook profile doesn't necessarily have to include the .pst file.

The AddStore method opens a .pst file in the current Outlook profile. Because you don't know the archive's display name beforehand, you can't assume it will be Archive Folder or Personal Folder. To prevent you from inadvertently moving files from the wrong archive, the script closes all Personal Folders in the Outlook profile. This step is important to note because the next time you open Outlook, you won't see your usual Personal Folders files in the folder hierarchy. The script then opens the old archive you specified and creates a new archive file. The AddStore method automatically creates a blank .pst file if the filename you specified doesn't exist.

A recursive method called CreateFolders traverses the old archive folders and creates the folders in the new archive, thus replicating the old archive's folder structure in the new archive. The CreateFolders method simultaneously checks each mail item in the folder it's processing to determine whether the CreationTime (i.e., the timestamp when the item was created) falls between the start and end dates you passed to the script through command-line parameters. If the item was created between these dates, the Move method moves the item into the new archive in the corresponding folder.

The script ends when all the mail items are processed. The last thing the script does is close the Outlook profile's archives. The script doesn't reclaim any space; to reclaim lost space, open the old archive and compact the folder. To accomplish this task, open the .pst file in Outlook, right-click the Personal Folders file, click Advanced, and click Compact Now.