Video Screencast Help

Working with WMIC to Gather Inventory Data

Created: 10 Dec 2012 • Updated: 10 Dec 2012
Language Translations
dougj's picture
+1 1 Vote
Login to vote

Working with WMIC to Gather Inventory Data

Microsoft’s wmic is a great little utility for quickly querying WMI classes. It is a very practicial tool for validiting Inventory Solution data. Following are a few insights and a batch file.

 

Interactive Mode

wmic has an interactive mode. Simply type, 'wmic' to enter interactive mode. A prompt similar to 'wmic:root\cli>' will be shown. Type 'quit' or 'exit' to return to a dos prompt. 

While in interactive mode, do not preface commands with 'wmic', just enter everything after 'wmic'. 

 

Default, Simple Commands:

The default command line is:      wmic path <class name>  get <attributes>

Examples:

wmic path win32_bios get *

wmic path win32_bios get biosversion, releasedate

Caption                                                             ReleaseDate
Phoenix ROM BIOS PLUS Version 1.10 A25  20100604000000.000000+000

 

The 'Where' Clause

The following are valid examples of using the where clause. Note that the value to match is enclosed in quotes and the 'get' statement has no parameters.

  • WMIC Path Win32_NetworkAdapter Where "Manufacturer='Realtek'" Get
  • WMIC Path Win32_NetworkAdapter Where (Manufacturer='Realtek') Get
  • WMIC Path Win32_NetworkAdapter Where (Manufacturer="Realtek") Get
  • WMIC Path Win32_NetworkAdapter Where "Manufacturer = 'Realtek'" Get
  • WMIC Path Win32_NetworkAdapter Where ( Manufacturer = "Realtek" And PhysicalAdapter = TRUE ) Get

 

Aliases:

wmi includes aliases to many, but not all, wmi classes. They can be found after the global switches in the output of 'wmic /?'. 

Example: 

wmic environment get name, variablevalue 

 
 

Useful switches

There are many switches but the following three are most useful for normal use:

  1. /format – reformats the data according to the specified format type.
  2. /output – outputs the results to the file name specified or to the clipboard.
  3. /namespace – changes the default namespace to the specified namespace

View all global switches by running: wmic /?

/format: Allows for specifying the output format. The default is ‘table’, which is difficult to read when the output wraps across multiple lines on the screen. Specifying alternate formats allows for easier reading of the output. Valid formats are:

  • CSV – comma-separated list
  • HFORM – creates entire, functional html page
  • HTABLE– creates entire, functional html page
  • LIST – vertical list of attribute=value pairs
  • MOF
  • RAWXML
  • TABLE – default, wrap-around format
  • VALUE– vertical list of attribute=value pairs (appears to be the same as ‘list’)
  • XML

 

Example:

This will list the attributes in attribute=value pairs, one per row, or vertically, as shown here:

wmic   path win32_utctime get * /format:list

Day=4
DayOfWeek=2
Hour=21
Milliseconds=
Minute=50
Month=12
Quarter=4
Second=8
WeekInMonth=2
Year=2012

 

/output – writes the output of the command to the specified file or to the clipboard rather than the DOS window.

/namespace – allows for querying namespaces other than the default, which is \\root\cimv2.

Examples:

wmic /output:myfile.html /namespace:\\root\cimv2\security\microsofttpm path win32_tpm get * format:hform

This command will:

  1. Query the win32_tpm class in the \\root\cimv2\security\microsofttpm namespace
  2. Format the list as an html form page with attributes listed vertically
  3. Output the results to ‘myfile.html’

 

wmic /output:CLIPBOARD path win32_utctime get * /format:list

This command will copy the output to the clipboard, allowing for pasting into another application.

 

One Step Further With HTML Output

The following batch file will query the specified wmi class, output the results to the specified file, add an .html extension, start the default application, presumably a browser, and open the specified file. The result is the ability to view the output in a readable html form in a browser.

This batch file is very simple (no error checking, help, etc.). It can be placed in any directory in listed in the path environment variable, etc. I suggest the name: wmic2browser.bat.

***********************************************
rem Parameters:
rem     %1 is the wmi class name
rem     %2 is the file name for the output

wmic /output:%2.html path %1 get * /format:hform
START "" "%CD%.\%2.html"
***********************************************

The result is similar to the following: