I am writing a script to do some server management. This script reads from a text file and then connects to each server and performs certain tasks.
One thing I am trying to build in is the ability to check if a server is online before it tries to perform any actions so that the script does not get hung up or fail when running a large list of machines.
My only guess was to do a ping check. I am doing this, but it is not working how I need it to. Here is the check and the function that I am using:
Now what is happening is that if the machine is pingable, it carries on and does its thing. However, once it encounters one that is not pingable, then it dies. I know it is because I am doing a quit, but what else can I do that would handle this?
This particular part is inside of a "For Each..Next" Loop that in turn is inside of a "Do While" loop that is reading a text file with server names in it.
Any ideas to do my "online" check or to fix what I am doing now?
One thing I am trying to build in is the ability to check if a server is online before it tries to perform any actions so that the script does not get hung up or fail when running a large list of machines.
My only guess was to do a ping check. I am doing this, but it is not working how I need it to. Here is the check and the function that I am using:
Code:
If Not IsPingable(objItem) Then
wscript.echo objItem & " is not pingable" & ";" & ";" & ";" & ";" & ";"
wscript.quit
End If
Function IsPingable(objItem)
Dim objShell, objExec, strCmd, strTemp
strCmd = "ping -n 1 " & objItem
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strCmd)
strTemp = UCase(objExec.StdOut.ReadAll)
If InStr(strTemp, "MS") Then
IsPingable = True
Else
IsPingable = False
End If
End Function
Now what is happening is that if the machine is pingable, it carries on and does its thing. However, once it encounters one that is not pingable, then it dies. I know it is because I am doing a quit, but what else can I do that would handle this?
This particular part is inside of a "For Each..Next" Loop that in turn is inside of a "Do While" loop that is reading a text file with server names in it.
Any ideas to do my "online" check or to fix what I am doing now?