WMIC - An Introduction
Windows Management Instrumentation (WMI) is an extremely powerful technology that provides tremendous detail on how a computer system is configured and operating. What makes WMI so attractive to Windows administrators is that you don't have to be a programmer to leverage it. WMI is available as a scripting option. There are many WMI VBScripts available online and as part of the Windows 2000/XP/2003 Resource Kits. With a little training and experience, you can develop your own WMI scripts. However all is not lost for those of you not inclined to learn the intricacies of developing a VBScript using WMI. XP includes a command line tool called WMIC which can execute WMI queries for you in a much simpler fashion. There is actually so much to explain about wmic that I can't possibly review it all. I'm only going to discuss enough information to get you started. I urge you to look at the information for wmic in Help & Support. WMI support is included in Windows 2000 and later systems by default.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
To use the tool, open a command prompt and type WMIC. The first time you run the program it does a mini-install of sorts. From there after, you will be presented with a wmic prompt (wmi:root\cli>). This is the utility's interactive mode. To quit the program just type 'exit' (without the quotes). You can also execute a full query at the command line which I'll cover at the end. Entering '/?' at the prompt will display help information.
As you see, to get information, you just need to know an alias for the component you are interested in. Unlike scripting where you would need to know a specific class name, you can get by with a simple name. At the wmic prompt, type in 'cpu'. You will get a report of cpu properties that scrolls off the screen. Typing 'cpu list brief' will return a subset of information. But it is still hard to read. For a better report, type 'cpu list /format:textvaluelist'. Other formatting options include CSV (/format:csv),raw XML (/format:rawxml), an HTML table (/format:htable) or an HTML page (/format:hform). If you want to save the output to a file, you can use the /Output switch. You can send output to the Windows clipboard (/Output:clipboard) or a file (/Output:osreport.csv). Be aware that you must put the output switch first in the command. For example, at the prompt type '/output:osreport.htm os list full /format:hform'. You can then open the file osreport.htm in any browser. If you specify a file name with spaces, you must enclose the name in quotes " ".
WMIC is nice but it's real power comes in managing remote systems. At the beginning of your command, simply use /node:servername, like this:
/node:FileSrv01 /output:c:\reports\filesrv01-cpu.htm cpu list /format:hform.
If you want to query multiple remote systems, separate computer names with commas (/node:computer1,computer2,computer3). Depending on the query you might also need to pass alternate credentials. At the beginning of the command, use /User and /Password. You can't use different credentials for local systems. Here is a more complete interactive example (this is one single line command from a wmic prompt):
/user:mydomain\Admin09 /password:P@ssw0rd node:FileSrv01,FileSrv02
/output:c:\reports\filesrv01-cpu.htm cpu list /format:hform.
I mentioned that you can also run commands directly from the command line. All you need to do is type wmic and then the wmic command you tested interactively:
wmic /node:FileSrv01 /output:c:\reports\filesrv01-cpu.htm cpu list /format:hform.
That's all there is to it. As I mentioned, WMIC can be a very useful utility and there is much more to it than I can cover here. In the mean time, open up a command prompt and try these commands to see for yourself. Don't worry, no changes will be made to your system, just a report of some local resources and elements. Depending on your system, some commands will provide more values than others.
wmic cpu list /format:textvaluelist
wmic os list /format:textvaluelist
wmic /output:mypc.htm computersystem list /format:hform [open mypc.htm in browser after you exit wmic to see the results]
wmic logicaldisk list brief /format:textvaluelist
wmic csproduct list /format:textvaluelist
Technorati Tags:
wmi
wmic
Windows Management Instrumentation
Scripting
I am unfamiliar with the format called “tvlist” and I apparently don’t have it on my machine (xp sp2). Is this one you created?
I also would like to be able to output the current node name when processing multiple computers. I know adding the /format:csv somehow inserts it, but I don’t know how to do that.
Thanks,
Glenn Wiens
[email protected]
I don’t know what that is now either. It might have been an artifact from copying text or who knows what. It probably should have been textvaluelist, which is what I’ve changed it to.
Getting the node name is automatic if you do something like this:
wmic /node:Server1,Server2,server3 /output:cpudata.csv cpu list /format:csv
And if you like WMIC, then you’ll love PowerShell, especially with WMI. Using WMI in PowerShell is so much easier and flexible.