Clear IIS Logs Using Task Scheduler

23/04/2014

This is something I see a lot, IIS logs takes a lot of space and sometimes even cause the IIS Server to stop due to “Not Enough Space” exception.

There is not a build in solution for Log retention policy but several options on File Size, Creation Scheduling etc.

There are many solutions for cleaning the Logs but I prefer the Task Scheduler way with a single line for cleaning Logs based on their creation date.

Run Task Scheduler from the Command Line

1. Open a command prompt. To open a command prompt, click Start , click All Programs , click Accessories , and then click Command Prompt .
2. At the command prompt, type Taskschd.msc .

Create new Task and specify “Start a program” in Actions Tab, enter “forfiles” in “Program/script:” section,

And “/p “C:\inetpub\logs\LogFiles” /s /m *.* /c “cmd /c Del @path” /d -2” in Arguments

(You can change -2 depends on the amount of days you want to keep your IIS Logs)

Full Command Line:

forfiles /p “C:\inetpub\logs\LogFiles” /s /m *.* /c “cmd /c Del @path” /d -2