Often times I find myself applying “developer-type” solutions to IT administrator problems. Naturally I was excited as PowerShell a.k.a Monad a.k.a Poshwas gaining notoriety. I had visions of a tool that would let me peek into services, filesystems, performance counters, etc. for all of my servers including database, application, web, etc. Much to my dismay, I quickly found that PowerShell only works locally! Total bummer, but it is a 1.0 product, so I am sure Microsoft had to do some feature triage. Things like AD and WMI took a back seat as there are other ways to get that data.
This means that the best way to query a server for administrative details such as OS version, patches, CPU, memory, running processes, services, etc is still to use Windows Management Instrumentation (WMI). In my opinion, using PowerShell 1.0 to call WMI is using a sledgehammer to kill a fly. This is fine, and it will certainly do the trick. However, if you don’t already know how to wield a sledgehammer, you may be explaining to your boss why it took 4 days to get a working script that one can do without PowerShell in 5 minutes. Enter WMIC – the command line tool for WMI.
It is amazing this thing doesn’t get more play, because it is awesome and comes built into most recent versions of Windows including Windows XP. WMIC is simple, elegant and very powerful. You can accomplish a tremendous amount in just one command line. This is much more straightforward, in my opinion, that using .NET or even PowerShell to crack open the functionality and data contained within WMI.
To show you how easy and awesome WMIC is, I invite you to try the following steps. Note there is no step to download anything because as long as you are using any modern version of Windows, it is included in the OS:
- Go to a command prompt and type the following command
- This will bring you to the WMIC command prompt. Now type
C:\Documents and Settings\your_id>
Notice the horizontal scrollbar in your results — there is a lot of information provided! This is essentially task manager on steriods. Better yet, it can be scripted out to a text file… on a schedule… etc… Pause for a minute and think about all of the things you can do with this. Now get ready to have your socks rocked off by the number of different items you can get information on. We used the “process” command to get information about the active running processes, but check this out (from within the wmic command prompt):
- At the WMIC command prompt type
Have fun exploring!!! Please post any comments here of useful tricks you have found using WMIC. Here are some other useful resources you may want to check out for more information on WMIC: