Wmi Script modification required

Hello, i've picked up some hints regarding wmi remote inventory scripts, i need it to collect very basic info on some networks.
This is the best i've come up and i could really use some changes on it:

-1 field i must have is the ipaddress from Win32NetworkAdapterConfiguration , i read it's stored as an array type so it scans the array for multiple values , etc, but i can't make it work and report all non null values :(

-Instead of having a dialog box requesting computer name would it be possible to have the input as a simple txt file with the computer names?

-Can the output be in csv format? i may have to run it in servers which  don't have office installed..so..

Thanks in advance for any help,

  Bruno



strComputer = InputBox ("Enter Machine Name")

Const NUMBER_OF_ROWS = 6
Const NUMBER_OF_COLUMNS = 2

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()

Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
objTable.Cell(1,1).Range.Text = "System Information For: "
objTable.Cell(2,1).Range.Text = "Manufacturer"
objTable.Cell(3,1).Range.Text = "Model"
objTable.Cell(4,1).Range.Text = "Domain Type"
objTable.Cell(5,1).Range.Text = "Serial Number"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
objTable.Rows.Add()
objTable.Cell(1, 2).Range.Text = UCase(strComputer)
objTable.Cell(2, 2).Range.Text = objItem.Manufacturer
objTable.Cell(3, 2).Range.Text = objItem.Model
Select Case objItem.DomainRole
Case 0 strComputerRole = "Standalone Workstation"
Case 1 strComputerRole = "Member Workstation"
Case 2 strComputerRole = "Standalone Server"
Case 3 strComputerRole = "Member Server"
Case 4 strComputerRole = "Backup Domain Controller"
Case 5 strComputerRole = "Primary Domain Controller"
End Select
objTable.Cell(4, 2).Range.Text = strComputerRole
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
For Each objItem in colItems
objTable.Cell(5, 2).Range.Text = objItem.SerialNumber

Next
objTable.AutoFormat(23)
bvqAsked:
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.

RobSampsonCommented:
Hi there, try this code for everything so far except for the IP address...I'll test at work shortly to get the IP...

Regards,

Rob.
strInputFile = "Computers.txt"
strOutputFile = "Results.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strResults = """Computer"",""Manufacturer"",""Model"",""Domain Type"",""Serial Number"""
While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	strResults = strResults & VbCrLf & """" & strComputer & """"
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
	For Each objItem In colItems
		strResults = strResults & ",""" & objItem.Manufacturer & """"
		strResults = strResults & ",""" & objItem.Model & """"
		Select Case objItem.DomainRole
			Case 0 strComputerRole = "Standalone Workstation"
			Case 1 strComputerRole = "Member Workstation"
			Case 2 strComputerRole = "Standalone Server"
			Case 3 strComputerRole = "Member Server"
			Case 4 strComputerRole = "Backup Domain Controller"
			Case 5 strComputerRole = "Primary Domain Controller"
		End Select
		strResults = strResults & ",""" & strComputerRole & """"
	Next
	
	Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
	For Each objItem in colItems
		strResults = strResults & ",""" & objItem.SerialNumber & """"
	Next
Wend
objInputFile.Close
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
MsgBox "Done. Please see " & strOutputFile

Open in new window

0
rejoinderCommented:
Here is the above with the network component.  Note: IP addresses = 0.0.0.0 are skipped.
strInputFile = "Computers.txt"
strOutputFile = "Results.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strResults = """Computer"",""Manufacturer"",""Model"",""Domain Type"",""Serial Number"""
While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	strResults = strResults & VbCrLf & """" & strComputer & """"
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
	For Each objItem In colItems
		strResults = strResults & ",""" & objItem.Manufacturer & """"
		strResults = strResults & ",""" & objItem.Model & """"
		Select Case objItem.DomainRole
			Case 0 strComputerRole = "Standalone Workstation"
			Case 1 strComputerRole = "Member Workstation"
			Case 2 strComputerRole = "Standalone Server"
			Case 3 strComputerRole = "Member Server"
			Case 4 strComputerRole = "Backup Domain Controller"
			Case 5 strComputerRole = "Primary Domain Controller"
		End Select
		strResults = strResults & ",""" & strComputerRole & """"
	Next
	
	Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
	For Each objItem in colItems
		strResults = strResults & ",""" & objItem.SerialNumber & """"
	Next
	
	Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
	For Each objNetAdapter in colNetAdapters
		arrIPAddress = objNetAdapter.IPAddress
		for n = lbound(arrIPAddress) to ubound(arrIPAddress)
			if arrIPAddress(n) <> "0.0.0.0" then
				strIP = strIP & "(" & arrIPAddress(n) & ") "
                        end if
		next
	next
        strResults = strResults & ",""" & trim(strIP) & """"
Wend
objInputFile.Close
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
MsgBox "Done. Please see " & strOutputFile

Open in new window

0
RobSampsonCommented:
Ah great.  Thanks mate, saves me the work ;-)

Rob.
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

rejoinderCommented:
No problem - just helping out where I can :-)
0
RobSampsonCommented:
Cool....I just noticed it's missing the extra header for the IP though....

This
strResults = """Computer"",""Manufacturer"",""Model"",""Domain Type"",""Serial Number"""

should now be
strResults = """Computer"",""Manufacturer"",""Model"",""Domain Type"",""Serial Number"",""IP Address"""


Regards,

Rob.
strInputFile = "Computers.txt"
strOutputFile = "Results.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strResults = """Computer"",""Manufacturer"",""Model"",""Domain Type"",""Serial Number"",""IP Address"""
While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	strResults = strResults & VbCrLf & """" & strComputer & """"
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
	For Each objItem In colItems
		strResults = strResults & ",""" & objItem.Manufacturer & """"
		strResults = strResults & ",""" & objItem.Model & """"
		Select Case objItem.DomainRole
			Case 0 strComputerRole = "Standalone Workstation"
			Case 1 strComputerRole = "Member Workstation"
			Case 2 strComputerRole = "Standalone Server"
			Case 3 strComputerRole = "Member Server"
			Case 4 strComputerRole = "Backup Domain Controller"
			Case 5 strComputerRole = "Primary Domain Controller"
		End Select
		strResults = strResults & ",""" & strComputerRole & """"
	Next
	
	Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
	For Each objItem in colItems
		strResults = strResults & ",""" & objItem.SerialNumber & """"
	Next
	
	Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
	For Each objNetAdapter In colNetAdapters
		arrIPAddress = objNetAdapter.IPAddress
		For n = LBound(arrIPAddress) To UBound(arrIPAddress)
			If arrIPAddress(n) <> "0.0.0.0" Then
				strIP = strIP & "(" & arrIPAddress(n) & ") "
			End If
		Next
	Next
	strResults = strResults & ",""" & Trim(strIP) & """"
Wend
objInputFile.Close
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
MsgBox "Done. Please see " & strOutputFile

Open in new window

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
rejoinderCommented:
Drat, just my luck.  I remember editing that line too.  I edited my file and didn't copy and paste the change to this web site.  C'est la vie.
0
RobSampsonCommented:
Don't worry about it....

Hey bvg, welcome to EE by the way!  Hopefully we have provided you with a good solution here.  Please don't hesitate to ask for any clarification.

Regards,

Rob.
0
bvqAuthor Commented:
Thank you guys for the help, works perfect :)
0
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.