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
1 2 3 |
root\cimv2 SELECT * FROM Win32_SystemEnclosure SMBIOSAssetTag |
Computer Manufacturer
1 2 3 |
root\cimv2 SELECT * FROM Win32_ComputerSystem Manufacturer |
Computer Model
1 2 3 |
root\cimv2 SELECT * FROM Win32_ComputerSystem Model |
Computer Serial
1 2 3 |
root\cimv2 SELECT * FROM Win32_BIOS SerialNumber |
Chassis Type
1 2 3 |
root\cimv2 SELECT * FROM Win32_SystemEnclosure ChassisTypes |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
' 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:
https://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.
I also use batch to run WMIC. Had good luck with it as well: http://betanews.com/2011/01/14/wmic-the-best-command-line-tool-you-ve-never-used/
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.
PowerShell:
gwmi win32_computersystem|select Manufacturer,Model
If you have a Dell:
gwmi win32_systemenclosure|select SBMIOSAssetTag
Thanks for your post, it helped me get the information I needed without loading the Dell Open Manage Client in WinPE 4.0.
Hi George,
Thanks for responding. You are right – you can use Power Shell to execute my above commands as well. gwmi is an abbreviation for Get-WmiObject cmndlet. More info can be found here: http://technet.microsoft.com/en-us/library/ee176860.aspx
I will update the bottom section to reflect using Power Shell as a ‘better’ alternative to VB Script.
Regards,
Ivan
Thank you, very much.