Solved

VB Script help

Posted on 2013-05-10
3
192 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
  • 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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