Monday, January 28, 2008

WMI Integration in Batch File Scripting

The two technologies that we are going to discuss are in themselves gigantic. Therefore finding an article on their integration was indeed pretty difficult. Therefore after a lot of scavenging I decided to write this account myself. Let us begin by defining the two terms:


WMI: An abbreviation for Windows Management Instrumentation. Microsoft describes WMI as a foundation stone for manageability in Windows operating systems. In todays blog we will be using WMI command line for the purpose of monitoring Server based systems in an enterprise environment. We are going to consider a few Operating system parameter, NIC features and drive disk information for our file. A full scale documentation on WMI can be found at the Windows Hardware Developer Central site.
Batch Files: A text file containing a number of commands that are executed by the command line interpreter are known as Batch Files. Usage of such files in day to day work has remained the most handy tool for a system administrator for automating normal procedures and by far the most effective.
Now lets us approach on the main batch file itself. In my scenario i got this batch file to run a loop of WMI command line arguments which would in turn collect all the necessary information for a selected number of servers which we can call from an external text file.The output for this procedure has been collected in a set of 4 HTML files.
The flow of the program file is going to be as follows:
-- Define the file itself.
-- Generate the master HTML file for storing the output.
-- Create a command interface so that the user understands that a scheduled task is being carried out.
-- Call the external server list for obtaining the hosts.
-- Perform the iterative loops and call WMIC with the necessary switches.
-- For each parameter define an HTML file and use the htform.xsl or htable.xsl which ever you feel is appropriate.
-- Close all the loops and then end the batch file.
This was one way of getting the batch file to do what I wanted. But, recently I came across a scenario where I just needed 2 parametric values. Therefore defining HTML file for each parameter in such a case would only burden my analysis. Hence,in such conditions the above flow can be slightly modified to get the output directly on the master HTML file by using the output switch in WMI.


Similarly, batch files along with WMI can be used to obtain the data in CSV format as well. Try using the above method for data analysis of your environment and I am sure you will be surprised by the time you save by automation of such processes. If you have question/queries please feel free to drop in a comment I will surely try to get you a solution.


That's all for now, till next time bye-bye ADMINS!!!


2 comments:

mohammed said...

YOUR GENIUS!!!!!!!!!!!!!!
its so simple and u make things more easy fr a person like me....

thank you friend

Anonymous said...

as fresher i would i understand to write the batch files to reboot the server can u giude me to write a script to reboot the server