Common WMI queries I have found useful

Below are some common WMI Queries that I have used, both during OSD (Operating System Deployment), startup/logon scripts or similar situations. I have broken them down to their most common form, and will show you how you can leverage this in a VB script at the end.

I will continue to update this post with new useful queries that I come across.

Common hardware WMI queries

Hardware Asset Tag

root\cimv2
SELECT * FROM Win32_SystemEnclosure
SMBIOSAssetTag

Computer Manufacturer

root\cimv2
SELECT * FROM Win32_ComputerSystem
Manufacturer

Computer Model

root\cimv2
SELECT * FROM Win32_ComputerSystem
Model

Computer Serial

root\cimv2
SELECT * FROM Win32_BIOS
SerialNumber

Chassis Type

root\cimv2
SELECT * FROM Win32_SystemEnclosure
ChassisTypes
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 Server
On 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:

' Sets computer name to the current computer name
strComputer = "."
' Connect to the WMI Service
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' Fetch all details from Win32_computersystem
Set colComputerSystem = objWMIService.ExecQuery ("Select * from Win32_computersystem")
Set colBIOS = objWMIService.ExecQuery ("Select * from Win32_BIOS")
' Look through all values, and make variables for manufacturer and model
For each objComputerSystem in colComputerSystem
	GetComputerManufacturer = objComputerSystem.Manufacturer
	GetComputerModel = objComputerSystem.Model
Next
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:

Get-WmiObject win32_computersystem | Select Manufacturer,Model

and the output can be seen here:

PS - WMI Manufacturer Model
As you can see once its in PowerShell the capabilities to manipulate and format the data is quite easy.

  1. Thank you, very much.

  2. PowerShell:
    gwmi win32_computersystem|select Manufacturer,Model

    • Thanks, its a post I have not updated in quite some time.
      With PowerShell being available on most servers and clients these days its become my preferred scripting language due to its power.

      Thanks for sharing – I will update my list to include more in the coming months.

Leave a Reply

QR Code Business Card
%d bloggers like this: