Common WMI queries


To totally unlock this section you need to Log-in


Login

Below are some common WMI Queries that we have used, both during OSD (Operating System Deployment), startup/logon scripts or similar situations. We 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.

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

Traditionally, the only way to identify the chassis type has been by visual inspection. However, the Win32_SystemEnclosure class can be used to determine the chassis type of a computer. Chassis types are stored as an array consisting of one or more of the values shown in the following table.

Value

Description

1

Other

2

Unknown

3

Desktop

4

Low Profile Desktop

5

Pizza Box

6

Mini Tower

7

Tower

8

Portable

9

Laptop

10

Notebook

11

Hand Held

12

Docking Station

13

All in One

14

Sub Notebook

15

Space-Saving

16

Lunch Box

17

Main System Chassis

18

Expansion Chassis

19

Sub Chassis

20

Bus Expansion Chassis

21

Peripheral Chassis

22

Storage Chassis

23

Rack Mount Chassis

24

Sealed-Case PC

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.

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:

Common WMI queries

As you can see once its in PowerShell the capabilities to manipulate and format the data is quite easy.

WMIC

The below commands should work on every edition of Windows (Windows 7, Windows 8, Windows 8.1, Windows 10) having wmic command tool available .

Just run the command given below to get computer model:

wmic csproduct get vendor, version

There’s another command which can be used to get the computer system model information. We can also get architecture (32bit/64bit) using the following command:

wmic computersystem get model,name,manufacturer,systemtype

Based on the information you require, you can use any of the above commands. These commands return the following information on our computer:

c:\>wmic csproduct get vendor, version
Vendor  Version
LENOVO  ThinkPad T410

c:\>wmic computersystem get model,name,manufacturer,systemtype Manufacturer - Model - Name - SystemType LENOVO - 2236EG1 - WINCMD-PC - x64-based PC

On another laptop, we could see the below output for the above two commands:

C:\WINDOWS\system32>wmic csproduct get vendor, version
Vendor - Version
Dell Inc.

C:\WINDOWS\system32>wmic computersystem get model,name,manufacturer,systemtype Manufacturer - Model - Name - SystemType Dell Inc. - Latitude E7450 - WINCMD-PC2 - x64-based PC

Find laptop model

You can use the below command to get the model of the laptop:

C:\>wmic computersystem get model
Model
ThinkPad T430

Another example:

C:\WINDOWS\system32>wmic computersystem get model
Model
Latitude E7450

This command would be useful to remotely fetch the model information from a bunch of computers in the network. We need to invoke this command on each of the computers and obtain the information.