DHCP Log Parser

I am sharing the script which I had created long time back for parsing DHCP Logs. This script will pull out computer name and IP address details for each log files placed in "DHCPLogs" folder and save the result in .CSV file.


Steps:

1. Copy the script in notepad and save as "DHCPLogParser.vbs" or whatever you like.

2. Create a folder named "DHCPLogs" in script directory.

3. Copy all DHCP Logs with folders / subfolders in "DHCPLogs" folder

4. Run the script

5. Result will be saved in DHCPLog-Parsed.csv file.

Dim objCurrentFolder

Set objFso = CreateObject("Scripting.FileSystemObject")

Set objResult = objFso.CreateTextFile("DHCPLog-Parsed.csv")

CheckFolder objFso.GetFolder ("DHCPLogs")

WScript.Echo "Done !!!"


'#### Sub CheckFolder

Sub CheckFolder(objCurrentFolder)

For Each objFile In objCurrentFolder.Files

'WScript.Echo "Processing " & objFile.Path & " ...."

ParseLogFile objFile.path

Next

'Recurse through all of the folders

For Each objNewFolder In objCurrentFolder.subFolders

CheckFolder objNewFolder

Next

End Sub


'####Sub ParseLogFile

'Extract only those lines where computer name is present

Sub ParseLogFile(strFileName)

Set objStream = objFso.OpenTextFile(strFileName)

Do While Not objstream.AtEndOfStream

strText = objStream.ReadLine

txtArray = Split(strText,",")



If UBound(txtArray) =7 Then

If txtArray(5) <>"" Then

objResult.WriteLine strText

End If

End If

Loop

End Sub


Comments

Popular posts from this blog

SCCM Software Distribution Troubleshooting

Powershell - List AD Organizational Unit and GPOs linked to them

Troubleshooting System Center Endpoint Protection (SCEP) Client