SYSTEMS MANAGEMENTUsing WMI Scriptingfor System AdministrationWindows Management Instrumentation (WMI), which offers administrators a richmanagement scripting tool set, is an integral part of the Microsoft Windows familyof operating systems—which includes Microsoft Windows 2000, Windows XP, andWindows Server 2003. This article introduces WMI, explains basic scriptingtechniques, and provides examples for automating systems management processesusing <strong>Dell</strong> OpenManage tools.BY SUDHIR SHETTYW indows® Management Instrumentation (WMI) is theunderlying management technology for Microsoft ®Windows operating systems. Based on industry standards,WMI helps enable consistent, uniform management controland monitoring of systems throughout an enterprise.WMI allows system administrators to query, change, andmonitor configuration settings on desktop and server systems,applications, networks, and other components ofthe IT infrastructure. System administrators can create awide range of systems management and monitoring scriptsthat work with WMI using the WMI scripting library.Overview of WMI architectureFigure 1 shows the three primary layers of the WMI architecture:WMI data providers, WMI management infrastructure,and WMI consumers.WMI data providersThe data providers retrieve information from managedresources. A managed resource is a logical or physicalcomponent that can be accessed and managed usingWMI. Examples of standard Windows resources that canbe managed using WMI include computer systems, disks,peripheral devices, event logs, files, folders, file systems,networking components, operating system subsystems,performance counters, printers, processes,registry settings, security, services, Microsoft ActiveDirectory ® directory service, Windows Installer, andWindows Driver Model device drivers. WMI data providersaccess the managed resources using the appropriateapplication programming interfaces (APIs) and exposethe data to the WMI infrastructure using a standardsbased,object-oriented data model.The operating system is bundled with standardproviders for accessing standard operating-systemresources such as processes, registry settings, and soforth. In addition, WMI enables software developersto add and integrate additional providers that exposedata and management functionality unique to theirproducts. For example, <strong>Dell</strong> provides a Common InformationModel (CIM) provider, which exposes additionalasset information through WMI. The <strong>Dell</strong>66POWER SOLUTIONS June 2004
SYSTEMS MANAGEMENTWMI consumersWMI scriptabout the C: drive, D: drive, and so on, can be retrieved by queryingthe CIMOM. Attributes, or properties, of this class, such asWMI scripting libraryFreeSpace, Name, and Size, can be queried remotely. Because theoperational state of most resources changes frequently, infor-WMI managmentinfrastructureCIMOM (WMI service)CIM repositorymation is typically read on demand to ensure that up-to-dateinformation is retrieved.CIM classes are organized into namespaces. Each namespaceWMI data providersWMI providerscontains a logical group of related classes representing a specific areaof management.WMI consumersManaged resources ormanaged objects(applications, devices, systems)WMI consumers are management applications or scripts thataccess and control management information available throughthe WMI infrastructure.Figure 1. Three primary layers of the WMI architectureOpenManage Server Administrator CIM Reference Guidecontains additional information on the data model supportedby this provider. The documentation is available online athttp://docs.us.dell.com/docs/software/svradmin.WMI management infrastructureThe WMI infrastructure consists of the Common Information ModelObject Manager (CIMOM), which manages the interaction betweenconsumers and data providers. All WMI requests and data flowthrough the CIMOM. The WMI service acts as the CIMOM and issimilar to other operating system services. For example, it can bestopped and started using the following commands:net stop winmgmtnet start winmgmtIntroduction to scriptingWindows scripting provides a rich environment in which administratorscan develop scripts. Scripts can access Component ObjectModel (COM) objects that support automation or standard accessmethodologies. This capability enables scripts to access COM-basedtechnologies, such as WMI or Active Directory Service Interfaces(ADSI), to manage Windows subsystems.The examples in this article use VBScript as the scripting languagebecause of its widespread usage. Other scripting technologies(for example, Microsoft JScript ® development software)that support COM automation can also be used to access WMIobjects. Available on Windows XP and Windows Server 2003 isa command-line tool for accessing WMI information, called WMIC(Windows Management Instrumentation Command-line).Figure 2 provides a simple example of a WMI script, whichlists the logical disk information for the local computer. To invokestrComputer = "."Management applications, administrative tools, Set objWMIService = GetObject("winmgmts:" _and scripts make requests to the CIMOM to retrieve& "{impersonationLevel=impersonate}!\\" & strComputer & _data, subscribe to events, or perform managementrelatedtasks. The CIMOM retrieves the provider and"\root\cimv2")Set colDisks = objWMIService.ExecQuery _("SELECT * FROM Win32_LogicalDisk")class information to service the request from the CIMrepository. The CIMOM uses the information obtainedConst CONVERT_TO_MB = 1048576from the CIM repository to pass the consumer requestFor each objDisk in colDisksto the appropriate WMI provider.WScript.Echo "Name:" & objDisk.NameThe CIM repository holds the schema, or object WScript.Echo "Size(MB):" & Int(objDisk.Size / CONVERT_TO_MB)repository, that models the managed environment. WScript.Echo "Free Space (MB):" & _CIM uses a rich object-oriented data model and the Int(objDisk.FreeSpace /CONVERT_TO_MB)notion of classes to represent information about managedresources. For example, a Win32_LogicalDiskNextclass represents logical disk information on a computer.Instances of this class, such as information Figure 2. Sample WMI script for listing logical disk informationwww.dell.com/powersolutions POWER SOLUTIONS 67