VBScript: Shortcuts for IIS Log Directories

I love parsing through IIS logfiles but I dislike the directory structure that Microsoft creates for IIS logging. Each site has a randomly generated directory name so, for example, “netnerds.net” could store its files in “C:\windows\system32\logfiles\W3SVC720199813.” Who wants to track that down? Not me! Use the attached script to change your ugly directory names into something that’s human readable.

'****************************************************************************
' This script created by Chrissy LeMaire ([email protected])
' Website: http://netnerds.net/
'
' NO WARRANTIES, etc.
'
' This script creates human readable shortcuts to your
' IIS logging directories.
'
' Requirements -- ability to read IIS:// and permissions to
' create subdirectories and files in your logging directory. If you encounter
' any problems, its probably because you don't have proper permissions.
'
' This script has only been tested on Windows Server 2003.
'
' "What it does"
' 1. Reads the master log file path (usually C:\windows\system32\logfiles)
' 2. Creates a directory called Shortcuts in the master log file path
' 3. Creates shortcuts to each directory using the website name
'    listed in the IIS websites tree. Done!
'*****************************************************************************

  Set objW3SVC = GetObject("IIS://localhost/W3SVC")
  MasterLogFilePath = objW3svc.LogFileDirectory
  shortcutDir = MasterLogFilePath & "\Shortcuts"

     Set fso = CreateObject("Scripting.FileSystemObject")
      If fso.FolderExists(shortcutDir) = FALSE Then
   fso.CreateFolder(shortcutDir)
   else
   fso.DeleteFolder(shortcutDir) 'empty it out..keep it clean. so you can run this every few months
   fso.CreateFolder(shortcutDir)
    End If
   Set fso = Nothing

For Each objSITE in objW3SVC
  If objSITE.class = "IIsWebServer" Then
   websiteName = objSITE.ServerComment
   w3LogFilePath =  objSITE.LogFileDirectory & "\w3svc" & objSITE.Name

    if  objSITE.LogType > 0 and objSITE.ServerState <> 4 then 'If logging is enabled and the website is running.

         set WshShell = CreateObject("WScript.Shell")
          set oShellLink = WshShell.CreateShortcut(shortcutDir & "" & websiteName & ".lnk")
          oShellLink.TargetPath = w3LogFilePath
          oShellLink.IconLocation = "explorer.exe, 13"
          oShellLink.Description = "Shortcut Script"
          oShellLink.Save
          set oShellLink = Nothing
          set WshShell = Nothing

      siteList = siteList & websiteName & " = " & w3LogFilePath & vbCrLf
       end if
   End if
  Next

MsgBox siteList 'or not

Chrissy is a Cloud and Datacenter Management MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in IIS
One comment on “VBScript: Shortcuts for IIS Log Directories
  1. Kev says:

    Hey I was the hardware tech for a small company here in NZ. Today I was promoted to IT guru in charge of our SBS 2003 (the real guy left and my boss remembered me fixing an old VB6 program a year or so ago)
    So my first job of the day was “check the IIS logs for…”
    Hmm where is the log and what do I read it with?

    Googled to here and your IIS.Microsoft.make.it.hard.jh2jgrhgeg7jhge to human script saved me. Now I have a shortcut to the site logs.
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*