locked
Parsing a txt file RRS feed

  • Question

  • I have a script that retrieves Make, model, service tag, ip address and mac address for my dell hardware and puts it in a CSV file. It works but I have to handjam each computername for it to retrieve the info .

    Current usage: c:\script>query.vbs computername username password

    I would like to export all my computers out of AD and have the script parse that .txt file. I not sure how I make the script take the txt file as input. Code is below.

    Any help would be greatly appreciated.

    set args = Wscript.Arguments  
    If args.Count <> 3 then  
    Wscript.Echo "Usage: cscript query.vbs computer_name username password"  
    Wscript.Quit 1  
    END IF  
    strComputer = args(0)  
    strUser = args(1)  
    strPass = args(2)  
     
    Set objFS = CreateObject("Scripting.FileSystemObject")  
    Set objNewFile = objFS.openTextFile("output.csv",8,True)  
    objNewFile.WriteLine "Host Name,Vendor,Model,Service Tag,IP Address,MAC Address"  
     
    Set objLocator = CreateObject("WbemScripting.SwbemLocator")  
    Set objSvc = objLocator.ConnectServer(strComputer, "root\cimv2", strUser, strPass)  
    objNewFile.write strcomputer & ","  
     
     
    Set colSWbemObjectSet = objSvc.InstancesOf("win32_computersystemproduct")  
    For Each objSWbemObject In colSWbemObjectSet  
    objNewFile.Write objSWbemObject.vendor & ","   
    objNewFile.Write objSWbemObject.name & ","   
    objNewFile.Write objSWbemObject.identifyingnumber & ","   
    Next  
     
    Set objWMIService = GetObject("winmgmts:" _  
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
     
    Set colAdapters = objWMIService.ExecQuery _  
        ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")  
       
    For Each objAdapter in colAdapters  
       
       If Not IsNull(objAdapter.IPAddress) Then  
          For i = 0 To UBound(objAdapter.IPAddress)  
            objNewFile.Write objAdapter.IPAddress(i) & ","   
         Next  
       End if  
     
    objNewFile.Write objAdapter.MACAddress & ","  
    next  
     
    objNewFile.WriteLine "" 
      
    • Moved by Yichun Feng Monday, December 29, 2008 9:50 AM Redirect to related VBScript forums for better support. (Moved from Visual Basic General to Off-Topic Posts (Do Not Post Here))
    Saturday, December 27, 2008 2:59 PM

All replies

  • The txt file will look something like this

    name
    name1
    name2
    name3
    name4
    name5
    Saturday, December 27, 2008 4:18 PM
  • Like the sticky at the top says, this is not a VBScript forum.  Look there for links, or check the Script Center on Technet.
    Thanks,
    Corey Furman
    Code Slabs
    ______________________________________________________
    Please mark posts as answer or helpful when they are.
    • Marked as answer by Yichun Feng Monday, December 29, 2008 9:21 AM
    • Unmarked as answer by Yichun Feng Monday, December 29, 2008 9:41 AM
    Saturday, December 27, 2008 10:30 PM