I can name that OS in one note

At the recent Techmentor conference in Orlando, I did a few (popular) sessions on using automating with batch files and using the command line. One tool I talked about was WMIC, or the WMI command line interface. This is available on Windows XP and later.  With this tool you can use WMI without having to know scripting or much about WMI. In fact, I can give you some WMIC commands to run that might be very helpful in your batch files.

First, if you’ve never used WMIC, open a command prompt and type: WMIC

You should get a  brief installation message followed by a WMIC prompt.  You can type exit to return to the command prompt. WMIC has an interactive mode like NSLOOKUP or you can access it directly from the command line.

Today I’ll give you an expression to return the current operating system and service pack on a given computer.

First, run this command to see your local system:

C:\> wmic os get caption,csdversion | find /i /v “Caption”

This will return something like:

Microsoft Windows XP Professional Service Pack 2

To check a remote system use a command like this:

C:\> wmic /node:”JDH-DC01” os get caption,csdversion | find /i /v “Caption”

If the computer name has a dash in the name, enclose it in “” as I did here. Since we’re talking about WMI, what about alternate credentials:

C:\> wmic /node:”JDH-DC01” /user:domain\admin /password:MyP@$$ os get caption,csdversion | find /i /v “Caption”

If the password has any special characters be sure to enclose it in quotes.

Finally, if you want to check several machines, you can either specify the computer names like this:

C:\> wmic /node:”jdh-dc01”,godot,dogtoy os get csname,caption,csdversion | find /i /v “Caption”

Or tell WMIC to use a text file of computernames:

C:\> wmic /node:@servers.txt os get csname,caption,csdversion | find /i /v “Caption”

I’ve added the CSNAME property so you get the computername as well. Otherwise, you might not be able to tell what OS goes with which computer.

That’s all for now.  I’ve just scratched the surface here. What do you think? Can you incorporate any of this into your batch files?  What would like to be able to do with this?

Technorati tags: , , , , ,