Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Script help

Posted on 2013-05-10
3
Medium Priority
?
201 Views
Last Modified: 2013-05-12
Obvious amateur with scripting and I need some help.

Here is the bit
On Error Resume Next

Dim FSO
Dim objStream

Const TriStateFalse = 0
Const FILE_NAME = "Report.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objStream = FSO.CreateTextFile(FILE_NAME, _
	True, TristateFalse)



strSubnetPrefix = "172.0.0."
intBeginSubnet = 60
intEndSubnet = 120

For i = intBeginSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
		if strcomputer = "" then
			wscript.quit
		else
		Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
			("select * from Win32_PingStatus where address = '" & strcomputer & "'")
		For Each objStatus in objPing
			If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then 
			else
				set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
			strComputer & "\root\cimv2")
				Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
				Set objItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
				For Each objComputer in colSettings 
				set objwmiservice = nothing
				set colsettings = nothing
				set objping = nothing
						objStream.WriteLine objComputer.name & "," & objcomputer.username & "," & strcomputer & "," & objcomputer.model
					For Each objItem in objItems
						objSteam.WriteLine objItem.serialnumber
					next						
					
				next
			end if	
		next
        end if
Next

Open in new window


What I am trying to do is query both Win32_ComputerSystem and Win32_BIOS and have it write to the same file... and I don't know what I am doing ;)
0
Comment
Question by:hQWeedEater
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 39157622
Hi, untested, but try this.  I think the main problem is that you were looping through the BIOS *while* looping through the COMPUTERSYSTEM, which means you'll loop it too much.

I've used only .Write for the first output, then .WriteLine for the rest.

Regards,

Rob.

'On Error Resume Next

Dim FSO
Dim objStream

Const TriStateFalse = 0
Const FILE_NAME = "Report.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objStream = FSO.CreateTextFile(FILE_NAME, True, TristateFalse)


strSubnetPrefix = "172.0.0."
intBeginSubnet = 60
intEndSubnet = 120

For i = intBeginSubnet To intEndSubnet
	strComputer = strSubnetPrefix & i
	If strcomputer = "" then
		WScript.quit
	Else
		Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
			("select * from Win32_PingStatus where address = '" & strcomputer & "'")
		For Each objStatus in objPing
			If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then 
			Else
				Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
				Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
				Set objItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
				For Each objItem in objItems
					objSteam.Write objItem.serialnumber & ","
				Next						
				For Each objComputer in colSettings
					objStream.WriteLine objComputer.name & "," & objcomputer.username & "," & strcomputer & "," & objcomputer.model
				Next
				Set objwmiservice = nothing
				Set colsettings = nothing
				Set objping = nothing
			End if	
		Next
		End if
Next

Open in new window

0
 
LVL 1

Author Closing Comment

by:hQWeedEater
ID: 39158240
Awesome, this works like a charm. Thank you very much!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 39159317
No problem. Glad to help. Thanks for the grade.

Rob.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question