Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have an IIS server on a Windows Server 2003 box where the log files keep filling up the hard disk. What I am looking for is a scheduled process that every once in a while will go in and clean up the logs, deleting anything older then a month. Does something like this already exist or is there a simple script out there I can use and setup as a scheduled task?

share|improve this question
You can configure IIS to use a different location for log files, they don't have to be on the system disk. – Richard Oct 12 '10 at 10:21
up vote 1 down vote accepted

Nothing like this is built into Windows, not at least Win2k3 or earlier. You can find dozens of scripts, in your language of choice, to accomplish this. I would use something like a BAT script that called forfiles.exe for anything over 30 days, and have it be scheduled to run daily using Scheduled Tasks.

Also, if your log files are on the system volume, move them to a different volume so when they fill the disk, they don't take the server down.

share|improve this answer
Thanks, I found/modified the following bat file using forfiles to delete log files older then 7 days. Forfiles -p D:\IISLogFiles -s -m *.log -d -7 -c "Cmd /C DEL @File" >> file.log 2>&1 – Peter Oct 12 '10 at 13:49
That will do it; I do the same thing on my laptop for clearing out PuTTY logs. Don't forget to mark the answer :-) – mfinni Oct 12 '10 at 14:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.