Login :: Register
General Topics
HostedbyMaximumASP170x35
2005 IIS MVPs
Other IIS Sites
  How can I find out what files are in my IIS log directory for a particular web site? 

The following script will show you the files contained in the log folder for a specific web site. You need to specify the Web Site Instance ID. This is the numeric number of the web site.

The easiest way to obtain this is to run a script called FINDWEB.VBS that is stored in one of the following locations

  • IIS5 = \inetpub\adminscripts
  • IIS4 = \winnt\system32\inetsrv\adminsamples

You call FINDWEB.VBS like this:

cscript findweb.vbs "Default Web Site"

and it will return with

  Web Site Number = 1
  Web Site Description = Default Web Site
    Hostname =
    Port = 80
    IP Address =

From this information we have determined that the web site is #1 and we use that for this script.

To call ShowLogFolderFiles.VBS like this:

cscript ShowLogFolderFiles.VBS 1

This will return a listing of the files in the log folder for the Default Web Site - (Instance ID = 1)

Log file dir for: IIS://LocalHost/W3SVC/3 = C:\WINNT\System32\LogFiles\W3SVC3

ex010311.cab                          1360   19/05/2001 06:35:02   110 days
ex010401.cab                           339   19/05/2001 06:37:46   110 days
ex010616.log                          6086   17/06/2001 11:10:50    81 days
ex010617.log                           352   17/06/2001 16:04:32    80 days
ex010622.log                           726   22/06/2001 23:44:46    75 days

Option Explicit
Const MaxAgeOfFileToShow = 0
Const GENERAL_FAILURE = 2
Dim ArgObj, Servername, WebSiteID, WebSite, WebSitepath, totalDeleted
Const WinDir = "%WinDir%"

function ExpandPath(Path)
 Dim key, ShellObject
 if (left(Path, 8) = WinDir) then
  Set ShellObject = WScript.CreateObject("WScript.Shell")
  Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PathName"
  ExpandPath = ShellObject.RegRead(Key) & mid(Path,9)
  Set ShellObject = Nothing
 else
  ExpandPath = Path
 end if
end function
function FormatValue(Value, MinWidth, AlignLeft)
   Dim Str
   Str = "                                       "
   Value = cStr(Value)
  if (Len(Value) < MinWidth) then
   if (AlignLeft = true) then
      FormatValue = Value+ left(Str, MinWidth-Len(Value))
   else
       FormatValue = left(Str, MinWidth-Len(Value)) & Value
  end if
else
   FormatValue = Value
  end if
end function
Sub ShowLogFolderFiles(WebSite,  WebSiteInstanceID, MaxAgeOfFile)
Dim File, ServerObj, FSO, FolderObj, FileObj, LogFileDir  , totalBytes 
totalBytes =0
Set ServerObj = GetObject(WebSite)
LogFileDir = ExpandPath(ServerObj.LogFileDirectory) & "\W3SVC" & WebSiteInstanceID
Set ServerObj = Nothing
WScript.Echo "Log file dir for: " &WebSite & " = " & LogFileDir
WScript.Echo ""
Set FSO = CreateObject("Scripting.FileSystemObject")
set Folderobj = FSO.GetFolder(LogFileDir)
for each File in Folderobj.files
  if (Date - File.DateCreated >= MaxAgeOfFile) then
         WScript.Echo formatValue(File.name, 30, true) & "  " & FormatValue(File.Size, 10, false) & "  " & _
  FormatValue(File.DateCreated,20, false) & " " & _
  formatValue(formatNumber(Date-File.DateCreated, 0) & " days", 10, false)
         totalBytes = TotalBytes + File.Size
  end if
next
WScript.Echo ""
WScript.Echo Folderobj.files.Count & " Files using " & formatNumber(TotalBytes,0) & " bytes."
end Sub
Sub DisplayHelpMessage()
    WScript.Echo
    WScript.Echo "Usage:"
    WScript.Echo "      ShowLogFolderFiles.VBS WebSiteNumber"
    WScript.Echo
    WScript.Echo "WebSiteNumber is the number of the web site, you have two methods to determine this:"
    WScript.Echo
    WScript.Echo "#1 = Run FINDWEB.VBS"
    WScript.Echo "#2 = Right click the web site, select properties, on the web site tab"
    WScript.Echo "     under logging click the Properties button, part of the log file"
    WScript.Echo "     name will contain the web site #"
    WScript.Echo
    WScript.Echo "     example log filename: W3SVC1\exyymmdd.log  - the web site is 1"
    WScript.Echo "                           W3SVC45\exyymmdd.log - the web site is 45"
    WScript.Echo
    WScript.Echo "Please visit and support : http://www.iisfaq.com"
end sub
' Get the Arguments object
Set ArgObj = WScript.Arguments
' Test to make sure there is at least one command line arg - the command
If ArgObj.Count < 1 Then
        DisplayHelpMessage
        WScript.Quit (GENERAL_FAILURE)
End If
Servername = "LocalHost"
WebSiteID    = ArgObj(0)
WebSite        = "W3SVC/" & WebSiteID 
WebSitepath = "IIS://" & Servername &"/" & WebSite
ShowLogFolderFiles WebSitePath,  WebSiteID, MaxAgeOfFiletoShow
 This site and its contents are Copyright 1999-2004 by IISFAQ Microsoft Corporation in no way endorses or is affiliated with IISFAQ