DOWNLOAD THE CODE:
Download the Code 38498.zip

The third script, which Web Listing 1 (http://www.winnetmag.com, InstantDoc ID 38498) shows, returns the same information as the second script, but instead of returning data to the screen, the third script writes data to a file. In this instance, the script appends data to a file on a network share that the script references through a Universal Naming Convention (UNC) path. The script prepares the data in a comma-separated value (CSV) format that you can import into a spreadsheet or database application. Notice in Web Listing 1 that the script replaces the Wscript.Echo commands with objTextFile.Write, removes the informational descriptions in quotes, and appends a comma to each piece of data to be written to the file. Additionally, the script executes a carriage return and line feed before closing the file.

Resources for Scripting with WMI
Although a .csv file probably won't satisfy all your requirements for inventorying desktop systems, you can employ additional scripting methods to output the information you've gathered to other formats, including XML. Likewise, you can use ActiveX Data Objects (ADO) to update a Microsoft SQL Server database.

The Microsoft TechNet Script Center (http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/ default.asp) is an excellent resource for finding sample scripts, including many that use WMI. In addition to providing general information about scripting, the TechNet Scripting FAQ (http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/scrptfaq.asp) provides a sample script that reports versions of key scripting components on your system along with links to download updates to these components. If you're unsure whether you have WSH or WMI, start here to avoid unnecessary frustration. And, of course, you can look through back issues of Windows & .NET Magazine (http://www.winnetmag.com) to find many great articles about using WMI scripting for administrative tasks.

Mining WMI
If you want to start from the ground up, you might consider some tools that will help you mine WMI. One such set of tools, Microsoft's WMI Administrative Tools, consists of WMI Event Viewer, WMI Event Registration Tool, WMI CIM Studio, and WMI Object Browser. The WMI Administrative Tools are available at http://www.microsoft.com/downloads/release.asp?releaseid=40804. WMI Object Browser is the most useful tool because it lets you drill down through the schema to view objects in the CIM repository. But the coolest tool for WMI scripting beginners is the recently released Scriptomatic tool, which is available at http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/wmimatic.asp. Scriptomatic lets you quickly generate WMI scripts with a few mouse clicks. Scriptomatic uses WMI to return a list of available classes into a dropdown list. When you select one of the returned classes, Scriptomatic generates a script that enumerates the values of the properties within that class. You can then run the Scriptomatic-generated script or save it for modification.

Starting Small
After you begin to realize the power of WMI, you can investigate other uses for administrative tasks you'd like to automate or perform remotely. Even if you don't see a use for WMI and scripting right now, keep it in mind as an alternative for those troublesome management tasks for which a tool doesn't exist.

End of Article

Prev. page     1 [2]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

 
 

ADS BY GOOGLE