If you're running a version of Microsoft Internet Information Services (IIS) on any of your servers, then you've probably seen what happens when IIS logs are not cleaned up periodically. Old IIS logs can quickly eat up all of the free space on the hard drive, especially on servers with highly utilized websites, such as Microsoft Outlook Web Access or line-of-business applications.
Instead of having to check and clear IIS logs manually, wouldn't it be nice to have a scheduled task that deletes the old logs automatically? The solution is easily implemented with a simple Visual Basic script and a scheduled task on each of the servers you want to keep cleaned up.
To clear the old IIS logs, or any type of log file that accumulates over time, you'll need to first save the script presented below with the extension of .vbs, such as delete_old_logs.vbs. I like to put all of the maintenance scripts I place on a server in a specific directory that I create, which in my case is C:\Program Files\Scripts. But you can save the script file anywhere on the server.
After the script has been saved on the server, you'll need to edit the script to specify the exact path that is to be cleaned and how many days of log files should be left. You'll find this information in the line that starts with Call CleanDirectory. In the example below, the script is set to delete the default IIS logs that are older than seven days. Be sure your folder path is inside the quotation marks, and remember that you can insert multiple Call CleanDirectory lines if you'd like to delete logs from several sources on the same server simultaneously. After making your changes to the script, be sure to save the script file.
The last step is to schedule a task to run the script file. The account that you run the scheduled task under needs to have permissions on the folders where the log files are located, so it's usually best to create a spec...
To continue reading for free, register below or login
To read more you must become a member of SearchWindowsServer.com