IIS creates a new log directory for each site and busy web applications can quickly consume web server disk space. Rather than manually open each folder and delete .log files, here is a script to delete Microsoft Windows IIS logs:
FORFILES /s /M *.log /D -2 /C “cmd /c del @path”
Just save to a .bat or .cmd and create a scheduled task to periodically run.
/s performs the action in subdirectories
/m *.log specifies the filetype
/d -2 deletes files older than 2 days. The current day’s log will be in use by IIS.
cmd /c del @path deletes files in the current cmd path (C:inetpublogsLogFiles)
If you are in an environment that requires various compliance, it is a good idea to zip and upload the log files. Some auditing standards require IIS traffic logs be kept for up to 7 years.
Posted with permission via the original article by the same author at Tritone Consultants