help with text file with computer names

Hey guys I am a newbie powershell guy and under normal circumstances would use the get-content command to pulll computer names. However, for this solution I only found that it can be done in vbscript. Can someone please kindly show me how I can do two things. The first is I have a text file full of computer names in a directory like c:\temp\computernames.txt I need to read from this instead of this array below.

Second thing is I need to put this info into a excel spread sheet. Please help thank you.

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_CoDriverVersion", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "Active: " & objItem.Active
WScript.Echo "InstanceName: " & objItem.InstanceName
WScript.Echo "NdisCoDriverVersion: " & objItem.NdisCoDriverVersion
WScript.Echo
Next
Next
techdriveAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Give this a try.  Save as a VBS, and run passing two filenames as in:

cscript EE26938950.vbs "c:\temp\computers.txt" "c:\temp\output.csv"


Then just open the CSV in Excel.

On Error Resume Next

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

' Get input and output file names from command line parms
If (WScript.Arguments.Count > 0) Then
  strInfile = WScript.Arguments(0)
Else
  WScript.Echo "No filename for computers specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  strOutfile = WScript.Arguments(1)
Else
  WScript.Echo "No filename for output specified."
  WScript.Quit
End If

' Create file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Read entire input file into a variable and close it
Set objInfile = objFSO.OpenTextFile(strInfile, ForReading, False, TriStateUseDefault)
strData = objInfile.ReadAll
objInfile.Close
Set objInfile = Nothing

' Open output CSV file
Set objOutfile = objFSO.OpenTextFile(strOutfile, ForWriting, True)
objOutfile.Write("Active,Instance,Version")

' Process each computer name from input file
arrComputers = Split(strData, vbCrLf)
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_CoDriverVersion", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      objOutfile.Write(objItem.Active & "," & objItem.InstanceName & "," & objItem.NdisCoDriverVersion)
   Next
Next 

' Cleanup and end
objOutfile.Close
Set objOutfile = Nothing
Set oFSO = Nothing
Wscript.Quit

Open in new window

~bp
0
techdriveAuthor Commented:
Works like a charm thanks and one last thing. I noticed on the output there is no way to tell what computer output what info. Is there a way to stick in some type of variable to output the hostname/computer name and then move on to the next machine.
0
Bill PrewCommented:
Try this change:

objOutfile.Write(strComputer & "," & objItem.Active & "," & objItem.InstanceName & "," & objItem.NdisCoDriverVersion)

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.