Common hardware WMI queries
Hardware Asset Tag
2 |
SELECT * FROM Win32_SystemEnclosure |
Computer Manufacturer
2 |
SELECT * FROM Win32_ComputerSystem |
Computer Model
2 |
SELECT * FROM Win32_ComputerSystem |
Computer Serial
2 |
SELECT * FROM Win32_BIOS |
Chassis Type
2 |
SELECT * FROM Win32_SystemEnclosure |
Note: I use the chassis type field to determine the whether it is a a mobile device (laptop or tablet) or a desktop. There is a problem at times because it is up to the OEM to determine the correct setting, and sometimes they get it wrong. Here are the codes that work most of the time.
8 = Tablet
9 = Laptop
10 = Laptop
11 = Laptop
14 = Laptop
Everything Else = Desktop or ServerOn the odd occasion, I need to override the above for certain models, like the Dell XPS which is given an 8 for tablet event though its an Ultrabook laptop.More info
How to use the WMI query?
There are many ways to utilise WMI, below are just a couple of examples on how to do this:
VBScript
Here is a quick snippet of where I use a WMI query to retrieve the Manufacturer and Model for the current machine using VB Script:
4 |
Set objWMIService = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" ) |
6 |
Set colComputerSystem = objWMIService.ExecQuery ( "Select * from Win32_computersystem" ) |
7 |
Set colBIOS = objWMIService.ExecQuery ( "Select * from Win32_BIOS" ) |
9 |
For each objComputerSystem in colComputerSystem |
10 |
GetComputerManufacturer = objComputerSystem.Manufacturer |
11 |
GetComputerModel = objComputerSystem.Model |
13 |
Wscript.echo "The system you are on is a " & GetComputerManufacturer & " " & GetComputerModel |
Simply save the above code as a .vbs file and execute it on a machine to see the results.
More detailed information can be found here on that particular script:
http://ivan.dretvic.com/2012/10/automatically-generate-description-field-for-computers-in-active-directory/
PowerShell
In a PowerShell window run the following command to extract the Manufacturer and Model of the hardware on the local machine:
1 |
Get-WmiObject win32_computersystem | Select Manufacturer,Model |
and the output can be seen here:
As you can see once its in PowerShell the capabilities to manipulate and format the data is quite easy.