WMIC – A Hidden Gem

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
  • C:\Documents and Settings\your_id> WMIC

  • This will bring you to the WMIC command prompt. Now type
  • wmic:root\cli> process

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
  • wmic:root\cli> /?

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:

http://technet.microsoft.com/en-us/library/bb742610.aspx

http://www.net-security.org/dl/articles/WMIC.pdf

    Advertisements

    TeamCity – A Better CCNet?

    I have heard some buzz about a product from JetBrains called TeamCity.  Some very influential technologists such as Roy Osherove seem to like the capabilities, so it is definitely worth a look.  This looks like a good competitor to CruiseControl.NET, so I think I am going to give it a spin.  I’ll update the blog here with my findings as I go along.  The installation sounds to be smoother than CCNet (which can be a bit painful), and some of the features on the TeamCity website look terrific.

    More to come, but if you have any experiences with TeamCity, please share them here in the comments.  My only concern at this point is that it looks like it may cater to more of a “Java” based crowd?  Sometimes tools with a Java history just don’t “feel” right to me and seem to take a long time to get the hang of for teams that are primarily involved with .NET.