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?
For some reason, that query doesn’t show that the server is at R2.
WMIC:
Microsoft(R) Windows(R) Server 2003, Standard Edition Service Pack 1
SRVINFO:
Product Name: Microsoft Windows Server 2003 R2
I do see that the ‘name’ property and the ‘othertypedescription’ show R2. The name property is multivalued though "Name=Microsoft Windows Server 2003 R2 Standard Edition|C:\WINDOWS|\Device\Harddisk0\Partition1"
I’ve also noticed "odd" things about how R2 identifies itself, or fails to identify itself. I don’t have an R2 box handy to test right now, but from work with clients, I think it also makes a difference if the server was upgraded to R2 or installed cleanly with R2. It may be that Microsoft is now making a distinction between OS and Product. I’ll have to dig into the MOF for Win32_Operatingsystem and see its definitions to get a better idea.
Jeff