Logrotate on Windows for Managing IIS Logs

I was recently trying to find a good solution for deleting old IIS logs files for our windows servers. I searched the web for anything equivalent to logrotate on linux for a Windows machine but had no luck (actually there was IISLogs, which was something you had to pay for). After much searching I stumbled across this Stackoverflow post which gave the simplest solution to the problem I was facing (we just needed to delete old log files).

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

This answer was posted by Reditus Solutions, LLC.

One issue I faced when creating a scheduled task with this command was the command would bring up prompts which would never receive a response and the task would just hang. You can add the /p flag (which silences all prompts) to the Del command: “cmd /c Del @path /p”

Advertisements