How to delete IIS log files on a windows 2003 SBS server

How to delete IIS log files on a windows 2003 SBS server older than 14 days.
You will need to install the Windows 2003 support tools otherwise you aren’t able to execute the command below. [ note: use the commands below via Notepad otherwise it’s not working because it’s seems like html code or what ]

Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c “Cmd /C DEL @File”

With

Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c “Cmd /C ECHO @File”

You could check if the script is working fine. After this you could make a Scheduled Task to run this script automatically .
Save the file was managelog.bat or cmd

4 thoughts on “How to delete IIS log files on a windows 2003 SBS server”

  1. Just used this in a script, but if you copy & paste it, it gives an error. The quote marks are not supported in the command prompt. You need to change them in an editor like notepad.

    1. I am trying to use this script on 2003 server and it says this:
      C:\Documents and Settings\Administrator>Forfiles -p C:\test3 -s -m *.* -d -5 -c
      “Cmd /C DEL @File”
      ERROR: Invalid syntax. ‘/C’ option is not allowed more than ‘1’ time(s).
      Type “FORFILES /?” for usage.
      do you know what i need to change to make this work? please
      pingram

  2. Well Pingram
    I tested just the command [ Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c “Cmd /C DEL @File” ] ( without the [ and ] via de command prompt on a windows 2003 service pack 2
    But what virtualpimp says you have to copy it first into notepad i didn’t write that at the time of the writing the post.
    So if you try to copy > past it to notepad and than copy past it to the command prompt [ cmd ] you will able to run the script.
    If you use note pad you have to type the full command over again in notepad otherwise you get the error you are showing to me.
    let me know if it works or don’t?

  3. Pretty sure the problem here is the use of smart quotes. Just retype the quotes in notepad after copy/pasting.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.