I have a script that reads a txt file line by line and then outputs to a CSV file. The issue I am having is when I run the script and I have multiple hostnames in the txt file it only pipes out the last hostname in the list to the csv file. Does anyone know how to modify this to pipe out all the hostnames and info to the csv file? Here is my code:
Any help will be appreciated.
Thanks.
Code:
Dim objFSO, objInFile, objOutFile, strFile, strOutData, strOutFile
strFile = "C:\ComputerInfo\List.txt"
strOutFile = "C:\ComputerInfo\Out.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(strFile)
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
strOutData = strOutDate & strComputer &"|" & strIPAddress & "|" & strMode & "|" & strSvcTag & "|" & strModel & "|" & strUsername & "|" & strMacaddress
Loop
Set objOutFile = objFSO.CreateTextFile(strOutFile)
objOutFile.Write strOutData
objOutFile.Close
Thanks.