Description and usage of WMIC Windows command
Posted: 28 Apr 2012 02:39
WMIC is a command included in the latest Windows versions and is one of the largest commands because the amount of information it may provide and the number of parameters it uses, but at the same time is one of the worst documented ones. WMIC is a command-line interface to Windows Management Instrumentation, that is Microsoft's implementation of the WBEM and CIM standards; you may review these terms in Wikipedia if you wish. In despite of that, I used the simplest way to explain WMIC usage, so I apologize if a purist does not agree. Although WMIC was designed to work through remote servers, it also may provide useful information in a single computer.
WMIC may display information about a very large number of computer resources, so you always must indicate the type of information you want via a resource name called alias; the simplest one is DataFile, that provide information about files. After the alias you may put a where clause, that select the desired data files, and a verb clause, that indicate the requested information. For example, the following command display all available information of all files in the disk (and take toooo long to complete):Verb clauses are: ASSOC, CALL, CREATE, DELETE, GET and LIST; the most useful one is GET [<property list>] where the most useful properties for DataFile alias are: CreationDate, Drive, FileExtension, FileName, FileType, LastAccessed, LastModified, Name, Path and Size, but there are more than 30 total properties for this alias!
The where clause take this form:where (propertyName=value [and propertyName=value] ...) although not all properties are allowed here. Note that path names in this clause must start and end with \\ and every intermediate \ in the path must be expanded to double \\; also, string values must be enclosed in quotes.
The Batch file below display the properties given in the parameters of the files in current directory, besides Name. Note that properties are always displayed in alphabetic order.
Properties.bat:For example:If /VALUE switch is added after the property list, the data is displayed in separated lines in PropertyName=value format (ready for a SET command!) instead of table format.
Another interesting alias are:Other useful alias (for me, at least) are: Bios, CDRom, CPU, DeskTop, DiskDrive, Environment, Job, LogicalDisk, OS, Printer, Process, Service, TimeZone and UserAccount, but there are more than 70 alias total!
Before the alias you may include global switches to modify the scope used by WMIC to retrieve or provide the requested information. The most useful ones are:I gather most of this information by executing wmic with various options and /? at end; for example: wmic /?:full. I also got some useful information from this site, excepting where clause usage that I got from here: w w w.robvanderwoude.com/wmic.php (besides several interesting examples).
I encourage you to add additional details on wmic usage if you know that for the benefit of all of us!
Antonio
WMIC may display information about a very large number of computer resources, so you always must indicate the type of information you want via a resource name called alias; the simplest one is DataFile, that provide information about files. After the alias you may put a where clause, that select the desired data files, and a verb clause, that indicate the requested information. For example, the following command display all available information of all files in the disk (and take toooo long to complete):
Code: Select all
wmic datafile
The where clause take this form:where (propertyName=value [and propertyName=value] ...) although not all properties are allowed here. Note that path names in this clause must start and end with \\ and every intermediate \ in the path must be expanded to double \\; also, string values must be enclosed in quotes.
The Batch file below display the properties given in the parameters of the files in current directory, besides Name. Note that properties are always displayed in alphabetic order.
Properties.bat:
Code: Select all
@echo off
set properties=Name
:nextParam
if "%1" == "" goto endParams
set properties=%properties%, %1
shift
goto nextParam
:endParams
set drive=%CD:~0,2%
set folder=%CD:~2%
wmic datafile where (drive="%drive%" and path="%folder:\=\\%\\") get %properties%
Code: Select all
properties CreationDate LastAccessed FileType
Another interesting alias are:
Code: Select all
wmic BaseBoard get Description, InstallDate, Manufacturer, Model, Name, SerialNumber, Version
wmic ComputerSystem get CurrentTimeZone, Description, InstallDate, Manufacturer, Model, Name, NumberOfProcessors, TotalPhysicalMemory
Before the alias you may include global switches to modify the scope used by WMIC to retrieve or provide the requested information. The most useful ones are:
Code: Select all
/TRACE:ON
Specify whether output debug information is to be copied to stderr.
/{OUTPUT|APPEND}:CLIPBOARD|<filename>
Specifies the mode and destination for output redirection.
I encourage you to add additional details on wmic usage if you know that for the benefit of all of us!
Antonio