I have a script that reads a txt file line by line a list of hostnames. Then it pipes out certain info from that pc to a csv file. When it gets to a hostname that is not on the network or not pinging it takes a while and pipes out the info of the last pc that was pinging. Can someone help me with the code that goes in the script that will ping the pc first and if it is on the network it will continue the script if not it pipes out PC not on network. Here is the code.
Code:
Option Explicit
On Error Resume Next
Dim objFSO, objInFile, objItem, objItem2, objOutFile, strFile, strOutData, strOutFile
Dim strComputer, strModel, strUsername, strMacaddress, strSvcTag, strIPAddress, intRamMB
Dim objWMIService, colItems, colItems2
Dim colComputer, objComputer
strFile = "C:\ComputerInfo\List.txt"
strOutFile = "C:\ComputerInfo\Out.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(strFile)
Set objOutFile = objFSO.CreateTextFile(strOutFile, True)
Do Until objInFile.AtEndOfStream
strComputer = objInFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
strSvcTag = objItem.SerialNumber
Next
set colItems2 = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem2 in colItems2
strUsername = objItem2.UserName
strModel = objItem2.Model
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
strMacaddress = objItem.Macaddress
next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
stripaddress = objitem.ipaddress(0)
next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
intRamMB = int((objComputer.TotalPhysicalMemory) /1048576)+1
next
strOutData = strComputer & "|" & strIPAddress & "|" & strSvcTag & "|" & strModel & "|" & strUsername & "|" & strMacaddress & "|" & intRamMB & vbCrLf & vbCrLf
objOutFile.Write strOutData
Loop
objOutFile.Close