Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to skip pc that is not on network. 1

Status
Not open for further replies.

EUTTECH

MIS
Dec 9, 2010
15
US
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
 
I think you might enjoy powershell. There's a little bit of a learning curve and a hiccup whilst getting your mind around the very different paradigm - but you soon realise that it is extremely powerful.

Enjoy your Xmas break
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top