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.

Image not found

Web path: https://blog.netnerds.net/images/sc.jpg

Disk path: /static/images/sc.jpg

Using Page Bundles: false

'**************************************************************************** ' This script created by Chrissy LeMaire ([email protected]) ' Website: https://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