我試圖修改一個現有的VBscript,從我的不同站點從服務器名稱從文本文件中拉出來,然後ping它們,服務器都被網站分組在一起他們位於。該腳本會在Excel頁面中顯示服務器是聯機還是脫機。這一切都可以正常工作,但腳本也嘗試ping站點的名稱。這裏的目標是主要通過在excel文件中顯示網站名稱來清理我的結果,但不會被ping通。 這裏是我當前的VBScriptVBS ping一組服務器但ping不通羣名
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 = "On Line"
objExcel.Cells(1, 3).Value = "Off Line"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("servers.txt")
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine
Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
objExcel.Cells(intRow, 1).Value = HostName
Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
Case 1 objExcel.Cells(intRow, 3).Value = "Off Line"
End Select
intRow = intRow + 1
Loop
objExcel.Range("A1:B1:C1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
這裏是文本文件的副本。
DISTRICT OFFICE
Server A
Server B
LAB
Server LA
School 1
Server 1A
Server 1B
School 2
Server 2A
Server 2B
School 3
Server 3A
Server 3B
Server 3c
你的'servers.txt'文件在哪裏?那包括網站嗎? – Marc
我編輯了問題以包含文本文檔的副本。這是否有幫助? –
想要ping的所有行條目都以「School」開始? – Sorceri