Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I just discovered that IIS builds up logs indefinitely and there don't appear to be any IIS settings that will automatically clean out old log files. What is the best way to keep my IIS logs under control so that they don't fill the entire hard drive?

share|improve this question
do you want to keep the old ones around in a zip archive, or delete them? –  Jeff Atwood Sep 14 '09 at 23:34
You are expected to manage the log files yourself. –  Evan Anderson Oct 20 '09 at 14:12

4 Answers 4

up vote 17 down vote accepted

You'll have to run a scheduled task to do it. Here's a Powershell script that should work.

set-location c:\windows\system32\Logfiles\W3SVC1\
foreach ($File in get-childitem) {
   if ($File.LastWriteTime -lt (Get-Date).AddDays(-30)) {
      del $File

This should purge anything that was last modified more than 30 days ago. Change the path in the first line to wherever your log files are stored. Also change the -30 to however long you want to retain the files. -30 means you will delete anything older than 30 days.

You can have a look at this article that shows different properties for the FileInfo object if you don't want to use LastWriteTime.

share|improve this answer

You could brew your own, but i believe some clever person has written this for you already. Check out IISLogs & IISLogs Lite!

If all your doing is deleting the logs, then you can turn logging off if its not needed! you will save your server a lot of I/O!

share|improve this answer

Well, if you want to clean them up regularly then why don't you disable request logging in IIS? You may use something like google analytics or some other service, I see many people dong this to avoid the headache with IIS logs affecting performance and eating up all disk space but it all depends on your requirements of course.

share|improve this answer

Create a scheduled task on the server. In the actions section, you want:

  • Action: Start a Program
  • Settings: Program= Forfiles
  • Add Arguments: -p "C:\inetpub\logs\LogFiles" -s -m . /D -45 /C "cmd /c del @path"
  • Start in: C:\

Give it a daily or weekly schedule. Done.

share|improve this answer

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.