Exchange: Managing SMTP and IIS Log Files via Script
Exchange can can log a number of transactions such as SMTP, IIS, or Message Tracking. These logs play an important role in troubleshooting, trending as well as a number of other things. However, Exchange or IIS does not provide an option to automatically purge SMTP or IIS logs. In this article, I will provide an example to manage these log files.
Since you want to always keep a copy of your log files, for example 30 days worth before purging them, what this script will do is first move all log files from the directory you specify to another partition E:\logs that are older than 30 days, then delete any log files older than 60 days from E:\logs.
1. Create a folder in C:\scripts (Or anywhere you want to designate)
2. Download WaRmZip from SoureForge. http://sourceforge.net/project/showfiles.php?group_id=88417&package_id=99571 Download file to C:\scripts
3. Open notepad and enter the following:
:: moves log files from the directory you specify below
waRmZip.wsf /r /q "C:\logs" /ma:30 /md:E:\Logs_Old
This script will move any log files older than 30 days from C:\logs to E:\logs_old folder. You will need to modify this line to point to where your SMTP or IIS logs are and your destination path. Save this file as movelogs.bat
4. Open notepad and copy the following:
:: Delete logs older than 60 days to run every 60 days.
waRmZip.wsf /r "E:\Logs_Old" /da:60 /df /q
Save this file as deletelogs.bat
5. Now go to scheduled tasks and schedule movelogs.bat to run monthly and deletelogs.bat to run every 60 days.
Note: Ensure you test this using test directories before implementing them into production. I have also provided these files on "Chong Man"s Exchange Resources" under links.
MCSE M+, S+, MCTS, Security+
How useful was this article? Want to see a tip not listed? Please leave a comment.