Script to clean out the Bad mail directory

Added 6/22/2004: Here is a link to a Microsoft page with their recommendation for cleaning out the BadMail folder:

If the ..\Program Files\ExchSrvr\Mailroot\vsi 1\BadMail is filling up with lot’s of files (.bad, .bdr., .bdp), you can simply delete them. However, it has been noted that if you have thousands of these files, simply deleting them may cause Exchange to slow to a crawl for awhile. It is therefore recommended to create a batch/command script that will clear this directory out. You can then schedule this scriupt to run daily or weekly, as required.

You may ask why this script doesn’t simply delete the files, but instead renames and deltes directories. That’s because of recommendations from Microsoft. Read more about this script at:

Here’s the actual script:

cd “D:\Program Files\Exchsrvr\Mailroot\vsi 1\”
echo !time!
net stop smtpsvc
ren badmail badmailold
md BadMail
net start smtpsvc
echo !time!
del badmailold\*.* /Q
rmdir badmailold
echo !time!

Note 1: You need to edit the file (see red) to reflect the drive where your Exchange folder exists
Note 2: The three “echo !time!” commands can be deleted, if desired.

3 thoughts on “Script to clean out the Bad mail directory

  1. hey there, I have the opposite problem. My badmail folder doesn’t fill up at all. I’m using the default badmail folder. It’s a little unnerving to not have *any* badmail given that the majority of issues concerning badmail are keeping it from getting out of control. Any ideas?

  2. If you’re running Exchange 2003 SP1 this behaviour is by design… Nothing is written to Badmail unless you configure it manually using registry values.

Leave a Reply

Your email address will not be published. Required fields are marked *