Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've google'd for this without much luck.. but I'm looking for an manual (one time run, free) / open source way to safely clear iis logs from /inetpub/logs/logFiles

I've seen ppl refer to, I have no idea how reliable that is, but even then I dont want any kind of scheduled task nor wish to pay for something i'm not really going to use often

I just want a simple safe way to delete all logs from inside the multiple folders in /inetpub/logs/logFiles

Recommendations or walkthroughs on how these can be removed would be appreciated.

share|improve this question
Why don't you just delete them in Explorer or on the command line? – barryj Jun 3 '11 at 10:40
Explorer looks like alot of hard work with the number of different folders. No idea how to do from the command line. + I cant stop IIS so the active log, whichever that is cannot be deleted. – asn1981 Jun 3 '11 at 10:44
i think you need to clarify the question a bit. You will have to have some sort of scheduled task to keep removing them or they will just grow and grow (unless you turn logging off). While iis is running nothing will be able to get rid of the current log, so you will have to stop it. I would write a batch file to stop iis in the middle of the night, then remove the logs, then star iis again – beakersoft Jun 3 '11 at 12:54
As I said this is a one-time run only task. I dont want to schedule anything but wish to save myself a few hours doing this manually. – asn1981 Jun 3 '11 at 13:00
The point is that this isn't a one-time-only task. For the duration of your time administering this server, you will need to keep a lid on log-file growth. The easiest way to do that is with a scheduled task that does the same thing every day (or week, whatever.) – mfinni Jun 3 '11 at 13:13
up vote 1 down vote accepted

Here is a script that deletes IIS logfiles older that 90 days

MaxDays = 90 
strComputer = InputBox("This script will delete IIS .log files over 90 days old "_ 
    & "from the machine you specify below.") 
wmiQuery = "Select * from Win32_OperatingSystem" 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colItems = objWMIService.ExecQuery(wmiQuery) 
    For Each objItem In colItems 
        sWindowsPath = objItem.WindowsDirectory 
Set objW3SVC = GetObject( "IIS://" & strComputer & "/W3SVC") 
    For Each objSite In objW3SVC 
        If objSite.Class = "IIsWebServer" Then 
            strLogDir = UCase(objSite.LogFileDirectory) 
                strLogDir = Replace(strLogDir,"%WINDIR%",sWindowsPath,1,1,1) 
                strLogDir = Replace(strLogDir,"%SYSTEMROOT%",sWindowsPath,1,1,1) 
                strLogDir = Replace(strLogDir,":","$",1,1,1) 
            objLogFolder = "\\" & strComputer & "\" & strLogDir 
            Set oFSO = CreateObject("Scripting.FileSystemObject") 
            Set oFolder = oFSO.GetFolder(objLogFolder) 
            Set colSubFolders = oFolder.Subfolders 
            For Each oSubFolder In colSubFolders 
                If InStr(UCase(oSubFolder),"W3SVC") Then 
                    For Each oFile In oSubFolder.files 
                        If InStr(LCase(oFile.Name),".log") Then 
                             If (Date - oFile.DateCreated > CInt(MaxDays)) Then 
                                oFSO.DeleteFile(oSubFolder & "\" & oFile.Name) 
                            End If 
                        End If 
                End If 
        End If 
MsgBox("All done.") 
share|improve this answer
How do I use this, where do I execute the script? – asn1981 Jun 3 '11 at 12:59
Copy this into notepad and save it somewhere as script.vbs, or something like that To run it open the command prompt and type cscript script.vbs. – Guido van Brakel Jun 3 '11 at 13:58
You save this as script.vbs and then you run it. – mfinni Jun 3 '11 at 13:58
Arh briliant thanks. I shall give this a try now. – asn1981 Jun 3 '11 at 14:31

You can use the /S flag to del to force it to delete files in subdirectories. The /Q flag will prevent it prompting you - omit it if you want to be cautious. So something like:

del /S/Q logdir\*.log

If you want to also delete sub-directories, you can use 'rmdir'. it has the same two flag options.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.