free web page hit counter

WMI / WMIC Scripting Guide

Wmic.exe is native to Windows XP and 2003. The Windows Management Instrumentation Command-line (WMIC) utility provides a command-line interface for Windows Management Instrumentation (WMI). WMIC is compatible with existing shells and utility commands. Wmic is a great addition to the already powerful WMI subsystem. One of the benefit's that immediatly jumps out is that you can send the output of wmic to a Comma Seperated Value (CSV) file, to XML, and to HTML output, as well as the standard screen output.

One of the other powerful features is the "/Every" switch, that allows you to repeat the command at a specified interval, in seconds. You can use the typical windows comman help shortcut "/?" after a command to see what commands are available to you.

Try some of these examples on your computer. When wmic is run on your computer for the first time, it can take a while to set itself up. After the first time it's run it will be much faster.

Note that it may be best to look at these commands from this Text link.

wmic /output:C:\Dsk.csv /namespace:\\root\cimv2 path Win32_LogicalDisk get FileSystem, FreeSpace, Size, VolumeSerialNumber, VolumeName, caption, description /format:csv.xsl

Example#1 Cpu statistics

Here is the output of the following command

wmic /output:C:\Proc.htm CPU get Description, DeviceID, Manufacturer, MaxClockSpeed, Name, Status, SystemName /format:hform.xsl

Node: XP-01 - 1 Instances of Win32_Processor

Intel(R) Pentium(R) 4 CPU 2.66GHz
Property NameValue
Description x86 Family 15 Model 2 Stepping 8
DeviceID CPU0
Manufacturer GenuineIntel
Name Intel(R) Pentium(R) 4 CPU 2.66GHz
Status OK
SystemName XP-01


Here is the same query with wmic to show you the putput in a CSV format.

wmic /output:C:\Proc.htm CPU get Description, DeviceID, Manufacturer, MaxClockSpeed, Name, Status, SystemName /format:csv.xsl

Node, Description, DeviceID, Manufacturer, MaxClockSpeed, Name,Status, SystemName XP-01, x86 Family 15 Model 2 Stepping 8, CPU0,GenuineIntel, 2657, Intel(R) Pentium(R) 4 CPU 2.66GHz, OK, XP-01

Scripting with WMIC.EXE

Something we should note also about WMIC, is that it automatically searches for every instance of an object, such as processors Harddrives, NIC's etc... there is no need to do any looping, of multiple searches as WMIC will automatically probe for each instance.

Here is an example script that searches for the majority of information an IT administrator would probably like to get a report on at least once a day. This script grabs, BIOS information, LogicalDisk(s) information, OS version, Memory information, PlugNPlay errors, and other computer information. Somthing you may notice is that LogicalDisk info will poll the mounted network drives as well as your CD-Rom, floppy etc... If you want strictly physical drives, use the Win32_ class of "Win32_DiskDrive", and to just get the Mapped drive use "Win32_MappedLogicalDisk" Everything is appended to a single file, and output is html.

Click here to view the output of this script (below)

wmic /output:C:\Inventory.html /namespace:\\root\cimv2 path Win32_LogicalDisk get FileSystem, FreeSpace, Size, VolumeSerialNumber, VolumeName, Caption, description /format:hform.xsl

wmic /append:C:\Inventory.html /namespace:\\root\cimv2 path Win32_ComputerSystem get CurrentTimeZone, Description, Domain, TotalPhysicalMemory, Model, Name, UserName /format:hform.xsl

wmic /append:C:\Inventory.html /namespace:\\root\cimv2 path Win32_BIOS get Name, SMBIOSBIOSVersion, SerialNumber, Version, BuildNumber, Status /format:hform.xsl

wmic /append:C:\Inventory.html /namespace:\\root\cimv2 path Win32_LogicalMemoryConfiguration get AvailableVirtualMemory, Caption, Description, Name, SettingID, TotalPageFileSpace, TotalPhysicalMemory, TotalVirtualMemory /format:hform.xsl

wmic /append:C:\Inventory.html /namespace:\\root\cimv2 path Win32_NetworkAdapter get Caption, DNSDomain, DNSHostName, DefaultIPGateway, Description, IPAddress, IPSubnet, MACAddress, S erviceName, WINSPrimaryServer, WINSSecondaryServer /format:hform.xsl

wmic /append:C:\Inventory.html /namespace:\\root\cimv2 path Win32_Processor get Caption, Description, DeviceID, Manufacturer, MaxClockSpeed, Name, Status, SystemName /format:hform.xsl

WMI script examples

The following links provide useful scripts that we've written, we hope you will get plenty of valuable information from them

These scripts were mainly derived from the Script-o-matic tool found on Microsoft's Site.

Inventory Script This script finds the following, Dell Service Tag from bios, cpu, memory, hardrive, Service Pack and network setting information. It will also report any hardware malfunctions that windows detects, basically when ever you'd see a yellow exclaimation point in system summary. The Dell service tag isn't really just a Dell thing, other Bios manufacturers use the "SerialNumber" field also. And on a similar note, if your looking for the dell service tag and are running Linux, try using DMI-Decode to obtain it. Output of the script

Here are some very good resources for WMI scripts also.

Microsoft's Scripting Center

The Scripting guy's archive

The Microsoft Script Repository