Problem solve Get help with specific problems with your technologies, process and projects.

Defragment Microsoft Outlook .PST files for better performance

Learn how you can use the Sysinternals Contig tool to defragment Microsoft Outlook .PST files and improve their performance.

As much as companies try not to use .PST files with Microsoft Outlook, sometimes they're simply unavoidable. If you have .PST files, I recommend using Sysinternal's Contig utility for general system optimization and to keep Microsoft Outlook .PST files running faster.

Mark Russinovich, the genius behind Sysinternals (now a Microsoft entity), created the Contig tool as a way to allow people to quickly defragment single files with as little overhead as possible. It's a command-line tool that uses the Windows defragmentation APIs; it takes a fragmented file and moves all of its clusters together into a single contiguous file.

Since the program doesn't use any undocumented variations on the APIs, it's perfectly safe. You can't lose data when using the program even if you pull the plug on the computer or suffer a crash.

Microsoft Outlook .PST files can grow quite large, so Microsoft Outlook performance can suffer if they're fragmented. As an example, my current 277 MB .PST file was defragged before I signed on this morning. After only half a day's use, it was already in 10 fragments.

The Contig tool can be used to defragment just the .PST file, so you don't have to defragment your whole system just to speed up the performance of that one .PST file. The way I've typically done this is with a batch file that runs Contig against all the files in my mail directory:

contig "%userprofile%\My Documents\My Email"

Note: The exact location of the mail directory will vary.

Because Contig works with the Windows defrag APIs, you can run it while Microsoft Outlook is also running and not suffer any ill effects.

The time it takes to defragment the Microsoft Outlook .PST file will vary depending on the speed of your system and the hard drive. During that time, the .PST file might be intermittently unavailable, or at least perform a little more slowly than normal. On my system, the 277 MB .PST file was defragmented in a matter of seconds. 

More on this topic

About the author: Serdar Yegulalp is editor of Windows Insight, a newsletter devoted to hints, tips, tricks, news and goodies for all flavors of Windows users.


Can I add switches to the contig bat file, such as –v, to see the results?

For example: contig –v %profile%/etc
—David B.


You can indeed do that, but if you're not around to see the process running you probably won't be able to tell what happened (since the console output won't be logged anywhere).

You can accomplish this by redirecting the output to a log file:

contig -v %profile%/etc > c:\logfiles\contig_log.txt

This is a very simple example, but with this you can see the results of the most recent Contig run no matter when it happened.
—Serdar Yegulalp, tip author


If the user does not have Admin privileges, I get "Access Denied" when I try and run this against their .PST file. As soon as I make the user an Admin it works fine. I'm unclear as to why Admin privileges would be required considering the user has full privileges to the directory location within their profile. Any ideas?
—Brian A.


The user might have full control over the files, but he might not have been granted the ability to perform the kind of file-system manipulation that the tool in question requires. It's basically the same restriction that prevents a user from running the DEFRAG command-line tool.

One way you can get around this is by creating a scheduled task which runs with Admin permissions; the Admin password is provided by an administrator and stored in an encrypted form, so the user doesn't need to know the password.

(This is also a way to run defrag without admin permissions -- just create a scheduled task for it that runs as admin during an off peak period when the PC is known to be on, so the user doesn't actually need to do anything.)
—Serdar Yegulalp, tip author


Does the Contig utility work with Windows XP Tablet PC Edition (and Microsoft Outlook 2000)?


Yes, I believe Contig works on all NT-based 32-bit versions of Windows, including XP Tablet Edition.
—Serdar Yegulalp, tip author

Do you have comments on this tip? Let us know.

Please let others know how useful this tip was via the rating scale below. Do you have a useful Exchange Server or Microsoft Outlook tip, timesaver or workaround to share? Submit it to If we publish it, we'll send you a nifty thank-you gift.

Dig Deeper on Exchange Server setup and troubleshooting