Solved

VB Script help

Posted on 2013-05-10
3
198 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

624 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