Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


May 2003

Scripting with WMI

Collect desktop inventory information directly from your system
RSS
Subscribe to Windows IT Pro | See More Windows Management Instrumentation (WMI) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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

   Previous  1  [2]  Next  


Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement