Text output format

  • Thread starter Thread starter Rick
  • Start date Start date
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
 
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
 
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
 
Back
Top