Wednesday, 10 September 2014

Vbs script to ping from .txt machine list txt

This is a script that will ping all the machines you put in the "Machinelist.txt" and report to an Excel file the result:

'===================================================
'
' NAME: Ping Script
'
' AUTHOR:   
' DATE  : 09/07/2013
'
' COMMENT: create file MachineList.Txt on C:\

'
'exemplary damages arising out of or in any way relating to the use of this script, 
'including without limitation damages for loss of goodwill, work stoppage, 
'lost profits, loss of data, and computer failure or malfunction. 
'You bear the entire risk as to the quality and performance of this script.
'
'=================================================

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 = "IP Address"

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.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, 2).Value = "Off Line"
End Select

intRow = intRow + 1
Loop

objExcel.Range("A1:B1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit 

0 commenti:

Post a Comment

Give me you feedback!