Using VBScript to Add Hostnames in CSV Logs

Written By: Kevin Jordan

- 24 May 2006 -

Description: Get your server logs ready for a database by using this VBScript to pull the hostname from a computer and add it to the beginning of each line in a .csv file.

  1. Creating the Logs and Calling the Script
  2. Helper Functions
  3. Adding to the CSV
  4. Pull it Together

Calling All Logs

Now what we need to do is call this function for each of the three logs we created earlier.

' Add hostname column to application logs
strFolderName = "\\CentralComputer\CentralLogs\New\App\"
strFileName = strFolderName & GetHostName() & "_" & Dateyyyymmdd(Date()) & ".csv"
Call AddToCSV(GetHostName(), strFileName)
 
' Add hostname column to security logs
strFolderName = "\\CentralComputer\CentralLogs\New\Sec\"
strFileName = strFolderName & GetHostName() & "_" & Dateyyyymmdd(Date()) & ".csv"
Call AddToCSV(GetHostName(), strFileName)
 
' Add hostname column to IIS logs
strFolderName = "\\CentralComputer\CentralLogs\New\IIS\"
strFileName = strFolderName & GetHostName() & "_" & Dateyyyymmdd(Date()) & ".csv"
Call KillTaskAborted(strFileName)                 ' Delete IIS 5.0 Logs
Call AddToCSV(GetHostName(), strFileName)

The first thing I do for each file is set the folder name and the file name. I do this mainly for readability. After that I call the AddToCSV() subroutine and let it do it’s thing. The one exception is on the IIS logs, where I called KillTaskAborted() first to get rid of those IIS 5.0 problems.

<< Previous