Trimming log files in windows

Trimming log files in windows

RRasco Mar 18, 2016

I know this is an old thread, but it shows up in search results a lot so I'm going to put this here in case anyone needs it.

These are the updated commands for deleting files and scheduling a task to remove W3SVC log files from Server 2012.

The Forfiles.exe command for deleting the files is the same as Robert3637 posted above.  Here it is for completeness:

Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c "Cmd.exe /C del @path"

I found plenty of other references online to scheduling this command as a task for 2008, but none for 2012.  So here is how I did it:

Create a batch file at "C:\inetpub\logs\LogFiles\W3SVC_LogsMaintenance.bat"

Put your Forfiles commands in that batch file you will need to create: W3SVC_LogsMaintenance.bat

My batch file contains´╗┐ two lines, one for each W3SVC folder:
Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -30 -c "Cmd.exe /C del @path"
Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC2 -m *.log -d -30 -c "Cmd.exe /C del @path"

I then scheduled this batch file to be called weekly on Sundays at 06:00.

Run this in a command prompt to create and schedule the task.

SCHTASKS /Create /SC Weekly /D SUN /ST 06:00 /TN "W3SVC Logs Maintenance" /TR "C:\inetpub\logs\LogFiles\W3SVC_LogsMaintenance.bat"

If you prefer to create and schedule the task via GUI, you can do so by launching the Task Scheduler or running this command to launch it.

    • Related Articles

    • Windows update stuck

          Click Start > Run > type “regedit” without the quotes, and accept the UAC prompt to continue     Navigate to HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate     Look at the keys in that folder, if they look something like this:     ...
    • Setting up backups

      To create backups  1. Go to and login 2. At the bottom select add new client 3. Under add new client behind NAT enter a descriptive name and click "add client" then click "Status" at the top 4.log in to backups on the client ...
    • Lets encrypt on Godaddy

      Home Subscribe LetsEncrypt SSL cert on GoDaddy Shared Hosting with No Root and No nc 23 February 2017 on letsencrypt, security, godaddy, wtf, sharedhosting, $ --issue -d -d -w ~/www --dns dns_gd Looks ...