Text output format

R

Rick

I'm using the following to ouput properties from the
Win32_ComputerSystem class. I want to include properties from the
Win32_OperatingSystem class on the same line as the
Win32_ComputerSystem class. I'm not sure how I would do this.

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem",,48)
For Each objItem in colItems

objFile.WriteLine objItem.Name & "," & objItem.Model "," &
objItem.Caption


Thanks in advance
Rick
 
M

Marty List

This is more of a VBScript question than WMI. You should store the WMI
values in variables, so you can use them later in your script. Also, you
should declare variables with "Dim" and always use "Option Explicit" as the
first line in your script.

Watch out for line wraps:

Option Explicit
Dim strComputer, objWMIService, colItems, objItem
Dim ComputerName, ComputerModel, ComputerCaption, OsCaption

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem",,48)
For Each objItem in colItems
ComputerName = objItem.Name
ComputerModel = objItem.Model
ComputerCaption = objItem.Caption
Next

Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
OsCaption = objItem.Caption
Next

objFile.WriteLine ComputerName & "," & ComputerModel & "," & ComputerCaption
& "," & OsCaption
 
R

Rick

Marty,
Thank you for the answer

Rick


Marty said:
This is more of a VBScript question than WMI. You should store the WMI
values in variables, so you can use them later in your script. Also, you
should declare variables with "Dim" and always use "Option Explicit" as the
first line in your script.

Watch out for line wraps:

Option Explicit
Dim strComputer, objWMIService, colItems, objItem
Dim ComputerName, ComputerModel, ComputerCaption, OsCaption

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem",,48)
For Each objItem in colItems
ComputerName = objItem.Name
ComputerModel = objItem.Model
ComputerCaption = objItem.Caption
Next

Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
OsCaption = objItem.Caption
Next

objFile.WriteLine ComputerName & "," & ComputerModel & "," & ComputerCaption
& "," & OsCaption
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top