WMI / WMIC Scripting Guide

WMIC.EXE

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:

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, ServiceName, 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