Solved

Hardware inventory collection

Posted on 2008-10-22
8
1,429 Views
Last Modified: 2008-11-07
Could someone help me to add option to this vbs script. What I like to have added is harddrive size, videocard type. The script was made by BobSampson.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22585270.html?sfQueryTermInfo=1+hardwar+script+wmi
0
Comment
Question by:QC20N
[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
  • 5
  • 3
8 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22782913
Hi, this should do it.

Regards,

Rob.
Option Explicit
 
'On Error Resume Next
Dim objFSO, wshNetwork, strComputer, objWMIService, colItems, strSerialNumber, strFileName, strResults, objItem, objOutputFile, strCPUDetails
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
' To convert to a logon script that runs without user interaction, add a rem in front of the strComputer = InputBox
' line below and remove the rem from the strComputer = "." line below that. This will then only check the PC on which
' the script runs
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = "."
 
' Get the serial number first to see if it already exists in the spreadsheet
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem In colItems
      strSerialNumber = "" & Trim(objItem.SerialNumber)
Next
Set objWMIService = Nothing
Set colItems = Nothing
 
strFileName = "\\server\share\Hardware Inventory\" & strSerialNumber & ".txt"
 
' Create Excel Spreadsheet
strResults = "Computername;Username;Manufacturer;Model;Serial Number;CPU;CPU Speed;Operating System;Service Pack;Total Memory;Hard Drive Size;Video Controller;Audit Date" & VbCrLf
 
' Get Computer System Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem In colItems
      strResults = strResults & Trim(objItem.Caption)  & ";" & Trim(objItem.UserName) & ";" & Trim(objItem.Manufacturer) & ";" & Trim(objItem.Model)
Next
Set objWMIService = Nothing
Set colItems = Nothing
'
'Output the Serial Number
strResults = strResults & ";" & strSerialNumber
 
'
' Get CPU Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem In colItems
      strCPUDetails = Trim(objItem.Name) & ";" & Trim(objItem.CurrentClockSpeed)
Next
Set objWMIService = Nothing
Set colItems = Nothing
strResults = strResults & ";" & strCPUDetails
'
' Get OS Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem In colItems
    strResults = strResults & ";" & Trim(objItem.Caption) & ";" & Trim(objItem.CSDVersion) & ";" & Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
Next
Set objWMIService = Nothing
Set colItems = Nothing
'
' Get Hard Drive Size
Dim strDiskSizes
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = 3")
strDiskSizes = ""
For Each objItem In colItems
	If strDiskSizes = "" Then
    	strDiskSizes = Trim(objItem.Name) & Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2) & "GB")
    Else
    	strDiskSizes = strDiskSizes & vbCr & Trim(objItem.Name) & Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2) & "GB")
    End If
Next
strResults = strResults & ";" & Trim(strDiskSizes)
'
' Get Video Card Type
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT Name FROM Win32_VideoController WHERE DeviceID='VideoController1'")
 
For Each objItem In colItems
	strResults = strResults & ";" & Trim(objItem.Name)
Next
'
' Get & Writeout current Date
strResults = strResults & ";" & Trim(Day(Now) & "-" & Month(Now) & "-" & Year(Now))
 
Set objOutputFile = objFSO.CreateTextFile(strFileName, True)
objOutputFile.Write strResults
objOutputFile.Close
 
Set objOutputFile = Nothing
Set objFSO = Nothing
 
MsgBox "Done"

Open in new window

0
 

Author Comment

by:QC20N
ID: 22783921
I can see in the txtfile that it collects:
Video Controller:
ConfigMgr Remote Control Driver

and not the name of the videocard.

And I would also, ask if the Combine hardware script in the same link can be used with this you are doing now?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22784059
Hi, so that I can determine how to read your Video Card name, please run the following code and let me know the results.

Regards,

Rob.
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /c cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
strComputer = "."
 
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_VideoController", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
   For Each objItem In colItems
      WScript.Echo "Caption: " & objItem.Caption
      WScript.Echo "Description: " & objItem.Description
      WScript.Echo "DeviceID: " & objItem.DeviceID
      WScript.Echo "DriverVersion: " & objItem.DriverVersion
      WScript.Echo "InfFilename: " & objItem.InfFilename
      WScript.Echo "InstalledDisplayDrivers: " & objItem.InstalledDisplayDrivers
      WScript.Echo "Name: " & objItem.Name
      WScript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
      WScript.Echo "SystemName: " & objItem.SystemName
      WScript.Echo "VideoArchitecture: " & objItem.VideoArchitecture
      WScript.Echo "VideoMemoryType: " & objItem.VideoMemoryType
      WScript.Echo "VideoMode: " & objItem.VideoMode
      WScript.Echo
   Next

Open in new window

0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 65

Expert Comment

by:RobSampson
ID: 22784067
And yes, the "combine" of the text files script can be used as well.

Regards,

Rob.
0
 

Author Comment

by:QC20N
ID: 22784153
Sorry to say. If I run the code a dos prompt shows and disappear again. Can't see the result.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22784176
Sorry....see this bit
%comspec% /c

change that to
%comspec% /k

and then run it again....

Rob.
0
 

Author Comment

by:QC20N
ID: 22784288
This is the result:

Caption: ConfigMgr Remote Control Driver
Description: ConfigMgr Remote Control Driver
DeviceID: VideoController1
DriverVersion: 4.00.6163.1000
InfFilename: oem23.inf
InstalledDisplayDrivers: ialmrnt5.dll
Name: ConfigMgr Remote Control Driver
PNPDeviceID: ROOT\*CM_RCDISPLAY\0000
SystemName: DKSODT0470
VideoArchitecture: 5
VideoMemoryType: 2
VideoMode:

Caption: Intel(R) 82945G Express Chipset Family
Description: Intel(R) 82945G Express Chipset Family
DeviceID: VideoController2
DriverVersion: 6.14.10.4543
InfFilename: oem6.inf
InstalledDisplayDrivers: ialmrnt5.dll
Name: Intel(R) 82945G Express Chipset Family
PNPDeviceID: PCI\VEN_8086&DEV_2772&SUBSYS_01AD1028&REV_02\3&172E68DD&0&10
SystemName: DKSODT0470
VideoArchitecture: 5
VideoMemoryType: 2
VideoMode:

Caption: Intel(R) 82945G Express Chipset Family
Description: Intel(R) 82945G Express Chipset Family
DeviceID: VideoController3
DriverVersion: 6.14.10.4543
InfFilename: oem6.inf
InstalledDisplayDrivers:
Name: Intel(R) 82945G Express Chipset Family
PNPDeviceID: PCI\VEN_8086&DEV_2776&SUBSYS_01AD1028&REV_02\3&172E68DD&0&11
SystemName: DKSODT0470
VideoArchitecture: 5
VideoMemoryType: 2
VideoMode:
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 50 total points
ID: 22790349
Thanks for that.  Try this.

Regards,

Rob.
Option Explicit
 
'On Error Resume Next
Dim objFSO, wshNetwork, strComputer, objWMIService, colItems, strSerialNumber, strFileName, strResults, objItem, objOutputFile, strCPUDetails
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
' To convert to a logon script that runs without user interaction, add a rem in front of the strComputer = InputBox
' line below and remove the rem from the strComputer = "." line below that. This will then only check the PC on which
' the script runs
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = "."
 
' Get the serial number first to see if it already exists in the spreadsheet
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem In colItems
      strSerialNumber = "" & Trim(objItem.SerialNumber)
Next
Set objWMIService = Nothing
Set colItems = Nothing
 
strFileName = "\\server\share\Hardware Inventory\" & strSerialNumber & ".txt"
 
' Create Excel Spreadsheet
strResults = "Computername;Username;Manufacturer;Model;Serial Number;CPU;CPU Speed;Operating System;Service Pack;Total Memory;Hard Drive Size;Video Controller;Audit Date" & VbCrLf
 
' Get Computer System Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem In colItems
      strResults = strResults & Trim(objItem.Caption)  & ";" & Trim(objItem.UserName) & ";" & Trim(objItem.Manufacturer) & ";" & Trim(objItem.Model)
Next
Set objWMIService = Nothing
Set colItems = Nothing
'
'Output the Serial Number
strResults = strResults & ";" & strSerialNumber
 
'
' Get CPU Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem In colItems
      strCPUDetails = Trim(objItem.Name) & ";" & Trim(objItem.CurrentClockSpeed)
Next
Set objWMIService = Nothing
Set colItems = Nothing
strResults = strResults & ";" & strCPUDetails
'
' Get OS Details
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem In colItems
    strResults = strResults & ";" & Trim(objItem.Caption) & ";" & Trim(objItem.CSDVersion) & ";" & Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
Next
Set objWMIService = Nothing
Set colItems = Nothing
'
' Get Hard Drive Size
Dim strDiskSizes
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = 3")
strDiskSizes = ""
For Each objItem In colItems
	If strDiskSizes = "" Then
    	strDiskSizes = Trim(objItem.Name) & Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2) & "GB")
    Else
    	strDiskSizes = strDiskSizes & vbCr & Trim(objItem.Name) & Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2) & "GB")
    End If
Next
strResults = strResults & ";" & Trim(strDiskSizes)
'
' Get Video Card Type
Dim strVideoController
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT Name FROM Win32_VideoController WHERE PNPDeviceID LIKE 'PCI\\VEN%'")
 
strVideoController = ""
For Each objItem In colItems
	strVideoController = Trim(objItem.Name)
Next
strResults = strResults & ";" & strVideoController
'
' Get & Writeout current Date
strResults = strResults & ";" & Trim(Day(Now) & "-" & Month(Now) & "-" & Year(Now))
 
Set objOutputFile = objFSO.CreateTextFile(strFileName, True)
objOutputFile.Write strResults
objOutputFile.Close
 
Set objOutputFile = Nothing
Set objFSO = Nothing
 
MsgBox "Done"

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 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