This script pings a list a list of servers from an excel sheet.
What the script does:
- get the server hostname from the excel sheet (c:tempservers.xls)
- the function CheckStatus does the wmi ping and returns true or false
- output is the hostname and the ping status
Follow the next steps to run the script (no admin rights needed):
- create an excel sheet with a list of hostnames
- save the sheet as c:tempservers.xls
- copy and paste the script in your favorite text editor
- save the script (for example c:tempalive.vbs)
- open a command prompt
- go to “c:temp”
- give “cscript alive.vbs” (without quotes) and enter
- output is the hostnames and status
The script:
' Name : alive.vbs
' Description : script to ping servers from an excel sheet
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 22-01-2010
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:tempservers.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
strHostname = objExcel.Cells(intRow, 2).Value
If strHostname <> "" Then
If CheckStatus(strHostname) = True Then
Wscript.Echo strHostname & " ; is alive"
Else
Wscript.Echo strHostname & " ; is dead"
End If
End If
intRow = intRow + 1
Loop
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
Function CheckStatus(strAddress)
Dim objPing, objRetStatus
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strAddress & "'")
For Each objRetStatus In objPing
If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode <> 0 Then
CheckStatus = False
Else
CheckStatus = True
End If
Next
Set objPing = Nothing
End Function
Happy scripting.
Best regards,
dirk adamsky
