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?
 
RobSampsonConnect With a Mentor Commented:
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
 
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
 
rejoinderConnect With a Mentor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

Rob.
0
 
rejoinderCommented:
No problem - just helping out where I can :-)
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.