Deleting old IIS Log Files

I was looking for an easy way to create a task to delete log files based on date for one of our IIS servers. The server gets thousands of hits an hour because of an information dashboard which is hosted on it. The logs aren’t important because they’re all internal and if it’s less than 7 days old we don’t care anyhow.

Based on information in the Technet forums, I ran the following command:

at 12:00 /EVERY:Su Forfiles.exe -p C:\WINDOWS\system32\LogFiles\W3SVC1 -m *.log -d -7 -c ”Cmd.exe /C del @path”

It should be fairly easy to follow…

  • At Midnight
  • Every Sunday
  • For the files in the log directory
    • Which are log files.
    • Which are older than 7 days
  • Delete them.

It’ll create a task called “At1” or whatever the ID it is that was created.



#IIS #Logs #Scripts #windows