I'm using this VBscript
code to ping a list of computers in a notepad and store the ping results in a csv file.
All computers stored in a notepad file are now availables (cmd >>> ping servername
), but the results in csv file are all DOWN.
I have tried also stored in notepad file one computer unavailable, but the results ping in a csv file are all DOWN...
Any suggestion?
My code below
dim strInputPath, strOutputPath, strStatus
dim objFSO, objTextIn, objTextOut
strInputPath = "C:\serverlist.txt"
strOutputPath = "C:\output.csv"
set objFSO = CreateObject("Scripting.FileSystemObject")
set objTextIn = objFSO.OpenTextFile( strInputPath,1 )
set objTextOut = objFSO.CreateTextFile( strOutputPath )
objTextOut.WriteLine("computer,status")
Do until objTextIn.AtEndOfStream = True
strComputer = objTextIn.ReadLine
if fPingTest( strComputer ) then
strStatus = "UP"
else
strStatus = "DOWN"
end if
objTextOut.WriteLine(strComputer & "," & strStatus)
loop
function fPingTest( strComputer )
dim objShell,objPing
dim strPingOut, flag
set objShell = CreateObject("Wscript.Shell")
set objPing = objShell.Exec("ping " & strComputer)
strPingOut = objPing.StdOut.ReadAll
if instr(LCase(strPingOut), "reply") then
flag = TRUE
else
flag = FALSE
end if
fPingTest = flag
end function