Welcome to the Blogcast Repository Sign in | Join | Help
Search BlogCastRepository.com for:
in Search

254 BlogCasts in The BlogCast Repository!

Ashish Fulgavkar

SCCM 2007, SMS 2003, Installshield, Scripting, Application Packaging and More...

Ping Script for Multiple Machines.

Do you want to ping a huge list of computers and find which are alive and not alive? Well the script below would be of help.

Prerequsites:

1. Copy the code below and create a VBS file (e.g. pingcomp.vbs)

2. Create a file for list of computers (e.g. Computers.txt)  note: Please make sure that you remove the last "Return" Char.

3. Both files mentioned above should be in the same location or folder. (I would suggest you create a folder like c:\ping and store the two files in this folder.)

What to expect :

1. After you run the script two files will be created in the c:\ping folder, viz

   a. Alive.txt which contains all the machines which responded to ping

   b. NotAlive.txt which will contain all machines which are not alive.

 

The Script is as follows.

 

'=======================================================================================================================================
'=======================================================================================================================================
' Ping.vbs

' Title................ : Script to Ping Machines

'=======================================================================================================================================
'=======================================================================================================================================
'Option Explicit


dim strMsg
dim DateM,DateD,DateY,DateH,DateMi
dim arrySecurityDescriptor
dim objFSO, objTSL,objTSR,objTSN
dim intTargetCnt
dim strComputer,strResult
dim vErrText
dim strListPath,strResultPath

strListPath = ""     

strResultPath = ""    


On Error Resume Next


Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTsL = objFso.OpenTextFile(strListPath & "computers.txt",1)                    ''''File to get the machine list.
Call ErrHandle("Opening List of Computers - " & strListPath & "computers.txt")   ''''Error handling if the file is unable to open.
Set objTsR = objFso.CreateTextFile(strResultPath & "Alive.txt",2)                      '''''File to store the results for later review.
Call ErrHandle("Opening Result File - " & strResultPath & "Alive.txt")                 '''''Error handling if the file is unable to open.
Set objTsN = objFso.CreateTextFile(strResultPath & "NotAlive.txt",2)                 '''''File to store the results for later review.
Call ErrHandle("Opening Result File - " & strResultPath & "NotAlive.txt")            '''''Error handling if the file is unable to open.

 

intTargetCnt = 0          '''''To Check the number of machines processed.

Do Until objTsL.AtEndOfStream
 strComputer = objTsL.ReadLine        '''''Getting the computer name.
 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
 Set colItems = objWMIService.ExecQuery _
     ("Select * from Win32_PingStatus " & _
            "Where Address = '" & strComputer & "'")
 For Each objItem in colItems
     If objItem.StatusCode = 0 Then
         'WScript.Echo "Reply received."         
  'objTsR.WriteLine ()
  objTsR.WriteLine (strComputer)
  'objTsR.WriteLine ()
              Else
   'WScript.Echo "No Reply received."         
  'objTsN.WriteLine ()
  objTsN.WriteLine (strComputer)
  'objTsN.WriteLine ()
             End If  
 Next

Loop


Sub ErrHandle(vActivity)        '''''Subroutine for handling the error in file operations.
 If err <> 0 Then
  vErrText = "There has been a problem with " & vActivity
  wscript.echo  vErrText & vbcrlf & string(Len(vErrText),"-") & vbcrlf & "Error Number : " & err.number & vbcrlf & " Error Description : " & err.description
  CleanUpAndGo
 End If
End Sub

 

 

Share this post:                                       

Comments

 

Pages tagged "dim" said:

January 19, 2008 6:50 PM