Categories: Uncategorized

Ping a list of machines from txt

This vbscript pings machines from a text file:

change the two variables for your input and output txt files:
strPATHout = “C:pingstatus.txt”
strPATHin = “C:pinglist.txt”

ON ERROR Resume Next

'Define log paths (disable in portions if not using a reference file)
strPATHout = "C:#activepingstatus.txt"
strPATHin = "C:#activepinglist.txt"

'Define additional variables here
sMsgboxtxt = "ping?" 'message box text here
sMsgboxttl = "ping?" 'message box title here
sLogTitle = "ping?" 'log file title string

'Standard message stating whether you want to do this or not
intReturn = Msgbox(sMsgboxtxt, vbYesNo, sMsgboxttl)
    If intReturn = vbNo Then
        Wscript.echo "Quitting"
        WScript.quit
    End If

'Create filesystem objects (comment out OBJin if not using reference file)
Set OBJfs = CreateObject("Scripting.FileSystemObject")
Set OBJin = OBJfs.OpenTextFile(strPATHin)
Set OBJout = OBJfs.CreateTextFile(strPATHout,True)

OBJout.WriteLine(sLogTitle & " - " & Now)

Do Until OBJin.AtEndOfStream
   strComputer = lcase(OBJin.Readline)

pingstatus = Ping(strComputer)
OBJout.WriteLine(strComputer & "," & pingstatus)
wscript.echo strComputer & "," & pingstatus

Loop

function Ping(sComputer)
    dim objShell, objPing, strPingOut, flag
    set objShell = CreateObject("Wscript.Shell")   
    set objPing = objShell.Exec("ping -n 3 -w 1000 "& sComputer)
    strPingOut = objPing.StdOut.ReadAll
    if instr(LCase(strPingOut), "reply") then
        flag = TRUE
 if instr(LCase(strPingOut), "destination host unreachable") then
 flag = FALSE
 end if
        else
            flag = FALSE
        end if
        Ping = flag
end function
'close the file
OBJout.Close()
OBJin.Close()
Wscript.echo "Quitting"

' Quit the Script ----------------------------------------------------
WScript.quit
TomLasswell

Share
Published by
TomLasswell
Tags: script

Recent Posts

Autotask: PowerShell: Enable Client Portal for all users

This is a quick one, it's been forever since I've posted here. After moving back…

2 years ago

PowerShell :: Get Exchange Mailboxes Over XXGB

Simple command turned crazy. I ended up coming up with this due to the fact…

4 years ago

PowerShell: ConnectWise Documents API, Uploading a document or attachment to a ticket

Phew, this one took a minute to figure out. ConnectWise has a form based documents…

6 years ago

PowerShell: ConnectWise REST API Query Contacts by Email Address

I've found myself at a new job, recreating many of the processes that I spent…

6 years ago

First post in a long time — changing hosting providers

Wow, it's been a while since I've done a real post on this site. I've…

7 years ago

Powershell: AutoTask – Get Picklist Values

When using AutoTask's API it's required to lookup a various amount of picklist values that…

10 years ago