Using WMI Scripting. W indows Management Instrumentation (WMI) is the. for System Administration



Similar documents
Proactively Managing Servers with Dell KACE and Open Manage Essentials

DELL OPENMANAGE CLIENT INSTRUMENTATION

Microsoft Visual Basic Scripting Edition and Microsoft Windows Script Host Essentials

DELL. Unified Server Configurator: IT and Systems Management Overview. A Dell Technical White Paper

Nagios XI Monitoring Windows Using WMI

Microsoft Operations Manager 2005

Administrator s Guide

HP Server Management Packs for Microsoft System Center Essentials User Guide

Using HP System Software Manager for the mass deployment of software updates to client PCs

Authoring for System Center 2012 Operations Manager

IBM WebSphere Application Server Version 7.0

Silect Software s MP Author

Server Manager Performance Monitor. Server Manager Diagnostics Page. . Information. . Audit Success. . Audit Failure

Administrator s Guide

Manage Dell Hardware in a Virtual Environment Using OpenManage Integration for VMware vcenter

HYPERION SYSTEM 9 N-TIER INSTALLATION GUIDE MASTER DATA MANAGEMENT RELEASE 9.2

Dell Repository Manager Tutorial

STATISTICA VERSION 9 STATISTICA ENTERPRISE INSTALLATION INSTRUCTIONS FOR USE WITH TERMINAL SERVER

HP Softpaq Download Manager and HP System Software Manager

Universal Management Service 2015

AdminStudio Release Notes. 16 July Introduction New Features... 6

AdminStudio Installation Guide. Version 2013

VERITAS Backup Exec 9.1 for Windows Servers Quick Installation Guide

Moving the TRITON Reporting Databases

Backup and Recovery FAQs

Troubleshooting Guide

HOUR 3. Installing Windows Server 2003

HP Insight Diagnostics Online Edition. Featuring Survey Utility and IML Viewer

TechNote. Contents. Overview. System or Network Requirements. Deployment Considerations

Windows PCs & Servers are often the life-blood of your IT investment. Monitoring them is key, especially in today s 24 hour world!

Dell SupportAssist Version 2.0 for Dell OpenManage Essentials Quick Start Guide

Lifecycle Controller Platform Update/Firmware Update in Dell PowerEdge 12th Generation Servers

Chapter 5: Operating Systems Part 1

Backup and Restore the HPOM for Windows 8.16 Management Server

Server & Application Monitor

VERITAS Backup Exec TM 10.0 for Windows Servers

Using Dell Server Diagnostic Tools

Metalogix SharePoint Backup. Advanced Installation Guide. Publication Date: August 24, 2015

SPECOPS DEPLOY / OS 4.6 DOCUMENTATION

Acronis Backup & Recovery 10 Server for Windows. Installation Guide

System Center Configuration Manager 2007

Installation & Maintenance Guide

System Management. What are my options for deploying System Management on remote computers?

HP SoftPaq Download Manager and HP System Software Manager A Powerful Combination

SQL Server 2008 R2 Express Edition Installation Guide

How to Configure Microsoft System Operation Manager to Monitor Active Directory, Group Policy and Exchange Changes Using NetWrix Active Directory

BMC Performance Manager Windows Security White Paper DCOM / WMI

Advanced Diploma In Hardware, Networking & Server Configuration

AdminToys Suite. Installation & Setup Guide

User's Guide - Beta 1 Draft

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 12

Integrating HP Insight Management WBEM (WMI) Providers for Windows with HP System Insight Manager

virtualization.info Review Center SWsoft Virtuozzo (for Windows) //

NetWrix Server Configuration Monitor

HPOM 8.1 High Availability Utilizing Microsoft SQL Server Log Shipping

Systems Management Tools And Documentation Version 8.1 Installation Guide

WhatsUp Gold v11 Features Overview

This document describes the installation of the Web Server for Bosch Recording Station 8.10.

HOW TO SILENTLY INSTALL CLOUD LINK REMOTELY WITHOUT SUPERVISION

Unicenter NSM Integration for Remedy (v 1.0.5)

Administration Guide. . All right reserved. For more information about Specops Deploy and other Specops products, visit

Using WMI Scripts with BitDefender Client Security

Spectrum Technology Platform. Version 9.0. Spectrum Spatial Administration Guide

Idera SQL Diagnostic Manager Management Pack Guide for System Center Operations Manager. Install Guide. Idera Inc., Published: April 2013

RES ONE Automation 2015 Task Overview

HP Insight Management WBEM Providers for Windows User Guide

Windows PowerShell Cookbook

FactoryTalk Gateway Getting Results Guide

Windows Server 2003 default services

Paul McFedries. Home Server 2011 LEASHE. Third Edition. 800 East 96th Street, Indianapolis, Indiana USA

Implementing a SAS Metadata Server Configuration for Use with SAS Enterprise Guide

Windows Server 2003 Logon Scripts Paul Flynn

User Guide. Version 3.2. Copyright Snow Software AB. All rights reserved.

UltraBac Documentation. UBDR Gold. Administrator Guide UBDR Gold v8.0

Table of Contents. FleetSoft Installation Guide

Windows 7, Enterprise Desktop Support Technician

SQL Server Solutions GETTING STARTED WITH. SQL Safe Backup

Microsoft Windows Storage Server 2003 R2

Symantec Enterprise Security Manager Baseline Policy Manual for CIS Benchmark. For Windows Server 2008 (Domain Member Servers and Domain Controllers)

Deep Freeze and Microsoft System Center Configuration Manager 2012 Integration

START YOUR INVENTORY WITH SCANFRE

TU04. Best practices for implementing a BI strategy with SAS Mike Vanderlinden, COMSYS IT Partners, Portage, MI

Inteset Secure Lockdown ver. 2.0

Setting Up a Unisphere Management Station for the VNX Series P/N Revision A01 January 5, 2010

QuickOPC Examples. Examples-QuickOPC.docx Page 1 of 19

Windows 7, Enterprise Desktop Support Technician Course 50331: 5 days; Instructor-led

Out n About! for Outlook Electronic In/Out Status Board. Administrators Guide. Version 3.x

Integrating idrac7 With Microsoft Active Directory

How To Manage A Data Center Remotely From A Computer Or Network Remotely

Windows Server 2012 Directory Partition Containers- A Walk Through

Installing and Administering VMware vsphere Update Manager

Dell Server Management Pack Suite Version 6.0 for Microsoft System Center Operations Manager User's Guide

Setting Up ALERE with Client/Server Data

Enterprise Vault Installing and Configuring

Pearl Echo Installation Checklist

How To Install An Archive Service On An Exchange Server (For A Free) With A Free Version Of Ios (For Free) On A Windows Xp Or Windows 7 (For Windows) (For An Ubuntu) (

Vector Asset Management User Manual

Transcription:

Using WMI Scripting for System Administration Windows Management Instrumentation (WMI), which offers administrators a rich management scripting tool set, is an integral part of the Microsoft Windows family of operating systems which includes Microsoft Windows 2000, Windows XP, and Windows Server 2003. This article introduces WMI, explains basic scripting techniques, and provides examples for automating systems management processes using Dell OpenManage tools. BY SUDHIR SHETTY W indows Management Instrumentation (WMI) is the underlying management technology for Microsoft Windows operating systems. Based on industry standards, WMI helps enable consistent, uniform management control and monitoring of systems throughout an enterprise. WMI allows system administrators to query, change, and monitor configuration settings on desktop and server systems, applications, networks, and other components of the IT infrastructure. System administrators can create a wide range of systems management and monitoring scripts that work with WMI using the WMI scripting library. Overview of WMI architecture Figure 1 shows the three primary layers of the WMI architecture: WMI data providers, WMI management infrastructure, and WMI consumers. WMI data providers The data providers retrieve information from managed resources. A managed resource is a logical or physical component that can be accessed and managed using WMI. Examples of standard Windows resources that can be 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 Active Directory directory service, Windows Installer, and Windows Driver Model device drivers. WMI data providers access the managed resources using the appropriate application programming interfaces (APIs) and expose the data to the WMI infrastructure using a standardsbased, object-oriented data model. The operating system is bundled with standard providers for accessing standard operating-system resources such as processes, registry settings, and so forth. In addition, WMI enables software developers to add and integrate additional providers that expose data and management functionality unique to their products. For example, Dell provides a Common Information Model (CIM) provider, which exposes additional asset information through WMI. The Dell 66

WMI consumers WMI script about the C: drive, D: drive, and so on, can be retrieved by querying the CIMOM. Attributes, or properties, of this class, such as WMI scripting library FreeSpace, Name, and Size, can be queried remotely. Because the operational state of most resources changes frequently, infor- WMI management infrastructure CIMOM (WMI service) CIM repository mation is typically read on demand to ensure that up-to-date information is retrieved. CIM classes are organized into namespaces. Each namespace WMI data providers WMI providers contains a logical group of related classes representing a specific area of management. WMI consumers Managed resources or managed objects (applications, devices, systems) WMI consumers are management applications or scripts that access and control management information available through the WMI infrastructure. Figure 1. Three primary layers of the WMI architecture OpenManage Server Administrator CIM Reference Guide contains additional information on the data model supported by this provider. The documentation is available online at http://docs.us.dell.com/docs/software/svradmin. WMI management infrastructure The WMI infrastructure consists of the Common Information Model Object Manager (CIMOM), which manages the interaction between consumers and data providers. All WMI requests and data flow through the CIMOM. The WMI service acts as the CIMOM and is similar to other operating system services. For example, it can be stopped and started using the following commands: net stop winmgmt net start winmgmt Introduction to scripting Windows scripting provides a rich environment in which administrators can develop scripts. Scripts can access Component Object Model (COM) objects that support automation or standard access methodologies. This capability enables scripts to access COM-based technologies, such as WMI or Active Directory Service Interfaces (ADSI), to manage Windows subsystems. The examples in this article use VBScript as the scripting language because of its widespread usage. Other scripting technologies (for example, Microsoft JScript development software) that support COM automation can also be used to access WMI objects. Available on Windows XP and Windows Server 2003 is a command-line tool for accessing WMI information, called WMIC (Windows Management Instrumentation Command-line). Figure 2 provides a simple example of a WMI script, which lists the logical disk information for the local computer. To invoke strcomputer = "." Management applications, administrative tools, and scripts make requests to the CIMOM to retrieve data, subscribe to events, or perform managementrelated tasks. The CIMOM retrieves the provider and "\root\cimv2") Set coldisks = objwmiservice.execquery _ ("SELECT * FROM Win32_LogicalDisk") class information to service the request from the CIM repository. The CIMOM uses the information obtained Const CONVERT_TO_MB = 1048576 from the CIM repository to pass the consumer request For each objdisk in coldisks to the appropriate WMI provider. WScript.Echo "Name:" & objdisk.name The 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 managed resources. For example, a Win32_LogicalDisk Next class represents logical disk information on a computer. Instances of this class, such as information Figure 2. Sample WMI script for listing logical disk information www.dell.com/powersolutions POWER SOLUTIONS 67

the script, save the listing into a file called disk.vbs and run the following command: C:> cscript disk.vbs Cscript.exe is a console-based scripting host that is packaged with the Windows Script Host (WSH) and is used for running scripts. Note that the script in Figure 2 can be adapted to access a variety of information about managed resources. Information about managed resources can be viewed by downloading WMI administrative tools from http://www.microsoft.com/downloads/details.aspx? FamilyId=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en. CIM Studio, which is bundled in the WMI administrative tool set, lets administrators view class information in the CIM repository. For other sample scripts that perform a variety of useful system administration tasks, visit Dell Power Solutions online at http://www.dell.com/magazines_extras. Figure 3 lists additional useful tasks that system administrators can script. Scripting to execute processes on remote Dell systems Administrators can write scripts to execute processes on remote systems, a technique that can be used in many ways to manage a Windows entity Description WMI-scriptable usage model Event logs Provide a repository of activities on Retrieve and query event logs a computer Configure event log properties Back up and clear event logs Printers Manage printers in the enterprise Monitor printers and print jobs Manage printer connections on client systems Registry Contains configuration settings for Create new registry entries the operating system, applications, Delete and update registry entries and services under Windows Back up the registry Files/folders Contain valuable enterprise data Manage files and folders (create, delete, and update) Enumerate files Manage shares Monitor the file system Disks and file Manage disks and file systems to Manage disk partitions system ensure continued access to data Manage logical disk drives Manage disk space Active Directory Manage user account information in Create user accounts users Active Directory Manage user accounts Delete user accounts Computer asset Contains an inventory of hardware Install, upgrade, and remove software information information, including the operating Retrieve system information, such as system and other software installed operating system, memory, and on the remote computer disk space Manage computer startup and recovery settings Computer roles Manage computers and computer Create, manage, and delete computer roles in Active Directory accounts in Active Directory Manage the roles assigned to computers Processes Manage running instances of an Monitor processes application or an executable file Create and terminate processes Enumerate additional process properties Figure 3. Examples of scriptable administrative tasks Based on industry network of Dell systems in the enterprise. Examples in this section illustrate the remote execu- standards, WMI helps tion of Dell OpenManage Server enable consistent, uniform Administrator command-line interface (CLI) commands on a Dell management control and PowerEdge server. To remotely execute other processes on target monitoring of systems nodes, administrators can customize these examples. A complete throughout an enterprise. command reference can be found in the Dell OpenManage Server Administrator Command-Line Interface User s Guide, which is available on the documentation CD that ships with every PowerEdge server or online at http://docs.us.dell.com/docs/software/svradmin. Figure 4 shows an example script that executes a process on a remote system. To invoke the script on a remote server, called MachineA in this example, save the preceding listing into a file called remote.vbs and run the following command: C:> cscript remote.vbs MachineA "omreport system esmlog outa c:\%computername%_esmlog.txt" The script in Figure 4 initiates the remote execution of the process and does not wait for the process to complete. Executing the script exports the Embedded Server Management (ESM) log into a text file on the remote target. This capability offers a rich set of possibilities for the remote scripting of PowerEdge Servers using Server Administrator CLI commands, including: omconfig: Configures values using the CLI. Administrators can use specific values for warning thresholds on components or prescribe what action a system should take when a certain warning or failure event occurs. Administrators can also use the omconfig command to assign specific values to a system s asset information parameters, such as the purchase price of the system, the system s asset tag, or the system s location. omdiag: Runs diagnostic tests against system hardware to isolate problems. omhelp: Displays short help text for CLI commands. omreport: Produces reports of a system s management information. omupdate: Installs the latest update packages for the system s BIOS, firmware, and drivers. Administrators can run sequences of these commands using a batch file on a remote managed node. For a sample script that executes a batch file on a remote node, visit Dell Power Solutions online at http://www.dell.com/magazines_extras. 68

strcomputer = WScript.Arguments.Item(0) strcommand = WScript.Arguments.Item(1) Wizard on the management station to perform the update during off-peak hours. "\root\cimv2:win32_process") errreturn = objwmiservice.create(strcommand,null,null,intprocessid) if errreturn = 0 Then Wscript.Echo strcommand & " was started with a process ID of " _ & intprocessid & "." Else Wscript.Echo strcommand & " could not be started due to error " & _ errreturn & "." End If Figure 4. Sample WMI script for executing a remote process Performing a remote software update under Dell OpenManage Administrators can perform a remote software update for BIOS, firmware, and drivers by using the omupdate command or by using a Dell Update Package. omupdate CLI command. To execute the omupdate command, an administrator would invoke the following: omupdate biosupdate path="\\network_share\file_name " This sample command refers to the network share where the update file resides. In the absence of a network share, administrators can copy the file to a temporary directory on the local system before performing the update. Dell Update Package. Another option is to copy the Dell Update Package, which is a self-contained.exe file, onto the remote system. The.exe file can be directly executed on the remote node by passing its command-line arguments for a silent installation of the package and rebooting the system, if necessary. The WMI script listed in Figure 5 illustrates a remote software update that passes in the computer name and the name of the Dell Update Package. In the script, note that the Dell Update Package is invoked with the /s /r option to perform a silent update and reboot of the system, if necessary. For a scheduled update, administrators can use the Windows Scheduled Task Security considerations WMI scripts run in the security context of the administrator running the script. To run scripts on a remote computer, a user needs administrative access on the remote system, thus helping to prevent malicious individuals from running destructive scripts on a remote server. Remote WMI scripting leverages Distributed COM (DCOM) for interacting with the WMI service running on the remote system. The scripts in this article set the impersonation level to impersonate. This setting implies that the WMI service uses the administrator s security context to perform the requested operation. If the administrator s security credentials are not adequate, errors such as Access Denied will occur when running the script. WMI provides a rich security infrastructure that can be configured on a per-namespace basis. By default, the administrator s group has full control of WMI on both local and remote computers, and users in other groups do not have remote access to the computers. To view a computer s security settings, invoke wmimgmt.msc from the command prompt, view the properties of the root node, and look strcomputer = WScript.Arguments.Item(0) strdupfile = WScript.Arguments.Item(1) '* First copy the Dell Update Package to the remote system Set objfso=createobject("scripting.filesystemobject") ObjFSO.CopyFile strdupfile, "\\" & strcomputer & "\C$\tmp\" & _ strdupfile '* Launch the process on the remote system "\root\cimv2:win32_process") strcommand = "C:\tmp\" & strdupfile & " /s /r" errreturn = objwmiservice.create(strcommand,null,null,intprocessid) if errreturn = 0 Then Wscript.Echo strcommand & " was started with a process ID of " _ & intprocessid & "." Else Wscript.Echo strcommand & " could not be started due to error " & _ errreturn & "." End If Figure 5. Sample WMI script for a remote software update www.dell.com/powersolutions POWER SOLUTIONS 69

PASSING ARGUMENTS THROUGH A TEXT FILE Several scripts in this article involve passing arguments through the command line. An alternative is to pass arguments as a text file. For example, to perform a software update on a set of PowerEdge 2650 servers, administrators can export an external database to list several servers in a text file, such as Server1, Server2, and Server3. This text file can then be passed as a command-line argument to the example script listed in Figure A. Set objargs = Wscript.Arguments Const ForReading = 1 Set objdictionary = CreateObject("Scripting.Dictionary") Set objfso = CreateObject("Scripting.FileSystemObject") Set objtextfile = objfso.opentextfile(objargs(0), ForReading) '* Read the file which contains a list of machines, one per line I = 0 Do While objtextfile.atendofstream <> True StrNextLine = objtextfile.readline objdictionary.add I, strnextline I = I + 1 Loop '* For each machine, retrieve the number of services running on that machine For Each objitem in objdictionary strcomputer = objdictionary.item(objitem) Wscript.Echo "Accessing remote machine" & strcomputer "\root\cimv2") Set colservices = objwmiservice.execquery _ ("SELECT * FROM Win32_Service") Wscript.Echo strcomputer, colservices.count Next Figure A. Sample WMI script for reading arguments from a text file at the security tab of the dialog box. Administrators can alter security settings at the namespace level and grant different permissions (remote access, method execution, or write) to different sets of users (domain or local). wmisdk/wmi/scripting_access_to_wmi.asp) and the book Microsoft Windows 2000 Scripting Guide by the Microsoft Windows Resource Kit Scripting Team provide additional valuable information about WMI and scripting. A powerful tool for performing administrative tasks WMI scripting is designed to provide a powerful mechanism that helps system administrators to perform remote administration tasks. The techniques presented in this article help provide an introduction to the power of WMI scripting. The Microsoft Web page Scripting Access to WMI (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ Sudhir Shetty (sudhir_shetty@dell.com) is a member of the Enablement Technologies team at Dell, working on systems management console solutions. He has more than 10 years of experience in designing and developing software components for user interfaces; database access; and networking in application areas such as systems management, systems prototyping and simulation, and tiered, distributed computing. Sudhir has an M.S. in Computer Science from The University of Texas at Austin. 70