Monday, 9 November 2015

Ping Test VBS

The following is a pretty handy Ping test script. I know it maybe should be PS but VBS is still handy.

on error resume next

Set objfso = CreateObject("scripting.filesystemobject")

Set objinputfile = objfso.OpenTextFile("machines.txt",1)
Set objOutputfileGood = objfso.CreateTextFile("PING-GOOD.txt",1)
Set objOutputfileFail = objfso.CreateTextFile("PING-FAIL.txt",1)

                Do Until ObjInputFile.AtEndOfStream
                                StrComputerName = objinputfile.ReadLine
                                strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & StrComputerName & "'"

                                ' Run the WMI query
                                Set colPingResults = GetObject
("winmgmts://./root/cimv2").ExecQuery( strQuery )

                                ' Translate the query results to either True or False
                                For Each objPingResult In colPingResults

                                If Not IsObject( objPingResult ) Then
                                objOutputfileFail.Writeline StrComputername
         ElseIf objPingResult.StatusCode = 0 Then
                                objOutputfileGood.Writeline StrComputername
         Else
                                objOutputfileFail.Writeline StrComputername
         End If
     Next


                loop

Wscript.Echo "Ping Test Completed"

No comments:

Post a Comment