Log file scrubber for IIS

I wrote this script quite a few years ago to reduce the size of IIS log files by removing log entries for trivial requests (based on file extension for the request).

The version below only removes successful log entries for any request for gif and jpg images. However, as they tend to make up a large portion of the log this can significantly reduce the size of the file, an improvement for long(er) term storage on busy servers.

It has a couple of short-comings. Error control is minimal, and reporting is non-existent.

' ScrubLogs.vbs
'
' Author: Chris Dent
' Date: 18/05/2005
' Modified: 07/06/2005
'
' Part of Log File Management. Removes successful file requests from targetted
' log files based on the contents of arrFileExtensions.
'
' Cannot be used on todays log file - locked by IIS.

Option Explicit

' The file extensions you want to remove successful requests for
Dim arrFileExtensions arrFileExtensions = Array("gif", "jpg") 

Function GetLogFolders(strServer)
    ' Returns a dictionary with log file path, site ID and
    ' comment for each site
    
    Dim objIISWeb, objSites, objNode
    On Error Resume Next : Err.Clear
    
    Set objIISWeb = GetObject("IIS://" & strServer & "/W3SVC")
    If Err.Number 0 Then
        WScript.Echo "Failed to connect to metabase: " & Err.Description
    End If
    On Error Goto 0
    
    Set objSites = CreateObject("Scripting.Dictionary")
    For Each objNode in objIISWeb
        If LCase(objNode.Class) = "iiswebserver" Then
            objSites.Add objNode.Name, Array(objNode.LogFileDirectory, objNode.ServerComment)
        End If
    Next

    Set objIISWeb = Nothing
    Set GetLogFolders = objSites
    Set objSites = Nothing
End Function

Sub ScrubFolders(objSites)
    ' Loops through objSites, checks the log file folder and checks files
    
    Dim strSite, strLogFolder
    Dim objFileSystem, objFolder, objFile
    
    Set objFileSystem = CreateObject("Scripting.FileSystemObject") 
    
    For Each strSite in objSites
        strLogFolder = objSites(strSite)(0) & "W3SVC" & strSite
        
        If objFileSystem.FolderExists(strLogFolder) Then
            Set objFolder = objFileSystem.GetFolder(strLogFolder)
            
            For Each objFile in objFolder.Files
                ' Skip files last modified within the last 24 hours 
                If objFile.DateLastModified 0 Then
                    booRemoveExt = True
                End If
            Next
            
            ' Write the line back to the new log unless it's a successful request
            ' for the file extensions we're removing
            If booRemoveExt = True Then
                int40x = InStr(1, Left(arrLine(intStatus), 2), "40", 1)
                int50x = InStr(1, Left(arrLine(intStatus), 2), "50", 1)
                If (int40x 0) or (int50x 0) Then
                    objTempFile.WriteLine strLine
                End If
            Else
                objTempFile.WriteLine strLine
            End If
        End If
    Loop
    
    ' Delete the original log file
    Set objStream = Nothing 

    strLogName = objFile.Name
    objFile.Delete
    Set objFile = Nothing
    
    ' Rename the temp file to match the original
    Set objTempFile = Nothing
    Set objTempFile = objFileSystem.GetFile(strTempFile)
    objTempFile.Name = strLogName
    
    Set objTempFile = Nothing
    Set objFileSystem = Nothing
End Sub

'
' Main Code
'

Dim objLogFolders
Set objLogFolders = GetLogFolders("localhost")
ScrubFolders objLogFolders
Set objLogFolders = Nothing