It's a non-issue for Exchange 2003 after SP1, however for those of us who still have Exchange 2000, or Exchange 2003 Pre-SP1 servers that we have to support this script might come in handy. At one point in time or another I'm sure that we have all run into a situation with the BadMail folder filling up quite a bit of space on the hard drive, or like the situation I was dealing with today, I keep getting alerts about viruses in that folder from the nightly scan's, and the antivirus software can't delete or clean the files for whatever reason. In any case I've written the following script which uses the "Badmailadmin" script from Microsoft to delete all messages from any and all Badmail folders on the server. You'll need to download the badmailadmin script from Microsoft in order to make it work. http://www.microsoft.com/downloads/details.aspx?FamilyId=782AAF0F-6239-40AD-ADDA-97863D852FF7


Script Name: Clear Exchange BadMail
Script Description: Clear out the contents of the Exchange "BadMail" folder, requires the Badmailadmin script from Microsoft http://www.microsoft.com/downloads/details.aspx?FamilyId=782AAF0F-6239-40AD-ADDA-97863D852FF7&displaylang=en

Per Microsoft's Specifications this script should only be run at low utilization times. By default this script will remove all messages, with different command line arguments it's possible to archive, or simply keep the BadMail Folder smaller than a specified size.

IF True
THEN
Write File
Parameter 1 : %TEMP%\badmailadmin.wsf
Parameter 2 : VSASharedFiles\badmailadmin.wsf
OS Type : 1
Execute File
Parameter 1 : %windir%\system32\cscript.exe
Parameter 2 : %TEMP%\badmailadmin.wsf -a delete -v all -f OLDEST -m 0 -l Events
Parameter 3 : 3
OS Type : 0
Write Script Log Entry
Parameter 1 : Removed BadMail Directories. See Event Log for details.
OS Type : 0
Delete File
Parameter 1 : %TEMP%\badmailadmin.wsf
OS Type : 0
ELSE




Legacy Forum Name: Exchange "BadMail" folder,
Legacy Posted By Username: Jonathan