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

Administrators have several choices when selecting tools that collect desktop inventory information for systems migration, auditing, or other purposes. In addition to Microsoft Systems Management Server (SMS), which is the company's tool for hardware and software inventory, several third-party tools are available that bolster SMS's inventory capabilities or operate on their own. In some organizations, however, the cost and complexity of deploying an inventory solution that's part of a larger management platform can present insurmountable hurdles to understaffed IT departments. In some cases, using scripts to cull system data directly from Windows Management Instrumentation (WMI) makes the most sense. For example, you can use a WMI-enabled script to return information about a system component that your existing inventory solution doesn't cover, or you can use WMI to gather information that you need for a rollout analysis without relying on a third-party inventory product.

Before we dig in to a WMI-based inventory solution, let's define WMI, where it came from, and what it can do. WMI is Microsoft's implementation of a scalable management standard that's built into Windows XP, Windows 2000, and Windows Me (WMI is also available as an add-on to Windows NT and Windows 9x). WMI is based on the Distributed Management Task Force (DMTF) initiatives, Web-Based Enterprise Management (WBEM), and the Common Information Model (CIM). As a result of being based on these standards, WMI provides a consistent, extensible management hook into the Microsoft OSs.

WMI Infrastructure
The WMI infrastructure consists of four components: WMI providers, the Common Information Model Object Manager (CIMOM), the CIM repository, and the WMI scripting library. WMI providers, many of which are built into the Windows OS and called standard providers, ensure that managed resources are available and addressed appropriately in WMI. CIMOM acts as a traffic director that handles interactions between WMI providers and consumers. The CIM repository is a schema that models and manages every piece of data available through WMI. The data is categorized into classes, and the classes are logically grouped into namespaces. Most computer- and OS-related information resides in the root\cimv2 namespace. The WMI scripting library is the interface through which scripting tools such as JScript, VBScript, and other languages (e.g., Perl) that support Microsoft ActiveScripting technology easily consume WMI data.

For the purposes of this article, you need to understand only that the sample scripts I describe are WMI consumers that use the WMI infrastructure to get information about, and sometimes control, managed resources. Retrieving data from WMI is just a small example of what you can do with WMI, but it's a good introduction to the potential of WMI scripting.

Rudimentary WMI Script Construction
Before you take the sample scripts from this article and manipulate them to get the information you're after, you'll want to review the basic constructs of WMI scripting. The first script, which Listing 1 shows, returns system processor information by performing the three basic functions common to WMI scripts: It connects to the WMI Service, retrieves information about a specific object, and outputs the gathered information. The first two lines connect to the WMI Service through the WMI Scripting Library "winmgmts:" on the local system "." and open the "\root\cimv2" namespace. The next line of the script returns instances of the specified WMI-managed resource, Win32_Processor, in the form of a collection. The last three lines of the script enumerate the contents of the collection in a For loop. If you create a text format file containing the contents of Listing 1 and save the file with a .vbs file extension, you can use Windows Script Host (WSH) to process the file. When you do so, a pop-up dialog box will display the information that the script enumerates.

More Powerful Scripts
What if you want to do more than just return the type of processor in your computer? You can accomplish more powerful results by expanding on WMI's basic functions. The second script, which Listing 2, page 78, shows, provides information about key system components to consider when you upgrade to XP. For example, if you're strapped for resources, you can use a variation of this script as a logon script to gather information you need to plan upgrades and system replacements necessary before you deploy XP. You can compare the results, which the script displays on your computer screen, to Microsoft's recommended processor, memory, disk space, video card, keyboard, mouse, CD-ROM drive, and network adapter requirements for XP.

   Previous  [1]  2  Next 


Top Viewed ArticlesView all articles
Microsoft, News Corp. Discuss Locking Out Google

Microsoft and Rupert Murdoch's News Corp. recently discussed an alliance that would counter Google's fledgling online news service. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

Command Prompt Tricks

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


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

Related Events 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