Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Hostfiles off multiple servers ?

Status
Not open for further replies.

GeorgeAdhaero

IS-IT--Management
Nov 25, 2010
3
GB
Hello,

I am performing a re-ip address and the previous system admins loved host files. What I am looking for is a script to go down a list of servers and query out the host file entries other than local host to a log file.

Does anyone have anythign like this ?

 
I have seen scripts that search for a specific entry eg this one;

'On Error Resume Next

Const ForReading = 1
SearchString = Inputbox ("Enter the Entry Value")

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

objExcel.Cells(1, 1).Value = "Server Name"
objExcel.Cells(1, 2).Value = "Target Entry"


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set InputFile = objFSO.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

objExcel.Cells(intRow, 1).Value = strcomputer

GetHostsEntry

intRow = intRow + 1

Loop

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Wscript.Echo "Done"

'************************************************************************************************

Sub GetHostsEntry



Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("\\" & strComputer & _
"\c$\WINDOWS\system32\drivers\etc\hosts")

If objFSO.FileExists(objFile) Then
Set objHostsFile = objFSO.OpenTextFile(objFile, ForReading)
Do Until objHostsFile.AtEndOfStream
strEntry = objHostsFile.Readline

SearchEntry = InStr(strEntry , SearchString)
If SearchEntry > 0 Then
strCurEntry = strEntry

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

End If

Loop

objHostsFile.Close

Else

objExcel.Cells(intRow, 2).Value = "Hosts File Not Exist"

End If

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top