VBS Script To Send DNS Server Record Data To Excel

 

This VBS script will write the following DNS Server information to an Excel spreadsheet: Resource machine name, IP Address, DNS server name and the Fully Qualified Domain Name or FQDN.

 

VBS Script:

 

strComputer = InputBox ("Enter DNS Server Name")

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Machine Name"

objExcel.Cells(1, 2).Value = "IP Address"

objExcel.Cells(1, 3).Value = "DNS Server"

objExcel.Cells(1, 4).Value = "FQDN"

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")

Set colItems = objWMIService.ExecQuery("Select * From MicrosoftDNS_PTRType")

For Each objItem in colItems

 

'Extract Name From FQDN Cell 4

CompNameArray = Split(objItem.RecordData,".")

For i = LBound(CompNameArray) to UBound(CompNameArray)

objComputer = CompNameArray(0)

Next

objExcel.Cells(intRow, 1).Value = UCase(objComputer)

 

'Extract IP Address From Reverse Lookup Record OwnerName And Reverse It

IPAddArray = Split (objItem.OwnerName, ".")

For i = LBound(IPAddArray) to UBound(IPAddArray)

IPAdd = IPAddArray(3) & "." & IPAddArray(2) & "." & IPAddArray(1) & "." & IPAddArray(0)

Next

objExcel.Cells(intRow, 2).Value = IPAdd

 

objExcel.Cells(intRow, 3).Value = objItem.DnsServerName

objExcel.Cells(intRow, 4).Value = objItem.RecordData

intRow = intRow + 1

Next

 

objExcel.Range("A1:D1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"

 

 

 

Published Sunday, September 28, 2008 1:50 PM by dhite
Filed under:

Comments

No Comments