Vous êtes sur la page 1sur 41

WMIC: A New Approach

to Managing Windows
Infrastructure from a
Command Line
Arkady Retik
Program Manager
Windows Server Division
Microsoft Corporation

Objectives

Review Windows Management


Instrumentation Command-Line (WMIC)
utility and its architecture
Demonstrate the modes of operation
Introduce the advanced use of WMIC

Agenda

Background
Architecture
Examples of use

Review
Advanced

Extending WMIC
Customizing WMIC
3

WMIC: WMI Command-Line Tool

Access various sources of


management data through WMI
without programming

A new tool: Only available on


Microsoft Windows XP
Professional and Windows .NET
Server Family products

Note: wmic pronounced [wee-mek]

Why WMIC?
Customers

IT administrators
Non-programmers
User interface to WMI

Value

Use of intuitive aliases


Simple ad hoc access to instrumentation
Extensible

Cons

Limited eventing support


5

Why WMIC? (2)


In fact, I think that WMIC is one of the best tool that
came out in the recent years, just because it gives
you the power of WMI without being a developer. Not
everybody in my team is familiar with WSH, VBScript
and WMI, so writing scripts that leverage WMI to
manage Windows servers could not be done by
anybody. With WMIC, they can, without knowing too
much about WMI itself - just great...
an IT Admin

Management Tools Strategy


Manageability Methods
Out of band
EMS (Remote Serial)

Remote Console
Cmd Line /
Simple scripting
WMIC

Remote GUI
Terminal Server
MMC
Web Admin
WMI Tools

Automated/preset
Policy
RIS
Automated setup

Para-programming/
Complex scripting

Command Line Tools Program

Admin focused
Pre-built .exe
Pre-built .vbs
Batch files
Redirection / Piping
WMIC adds extensibility

Programmer or sophisticated admin

Build your own tools or complex scripts


Win32 APIs
COM Objects
WMI & ADSI interfaces for scripting

Command-Line Tools Program

Simplicity
Top tasks covered with new command-line
tools
Admin focused, easy, and pre-built
Automation enhancements

Power and extensibility


WMIC new WMI command-line interface
Exposes all WMI management data
Customize queries for any scenario

Windows Management
Instrumentation (WMI)
Goals

Make Windows the most


manageable OS
Provide a comprehensive
management infrastructure,
removing the need for
management agents
Enable system and application
observation and control
Consistent queries

Consistent methods
Consistent events
Consistent protocol
Consistent schema

Availability

Windows 95
Windows 98
Windows NT 4.0
Embedded NT
-------------------Windows 2000
Windows Me
Windows XP
Windows .NET Server

Partners (redistributed
w/ OEMs / ISVs / IHVs)

WMI Architecture Point-to-Point


WBEM
Consumer

C:\>

Script

SWBEM

ODBC
Adapter

ODBC
Client

ADSI Ext.
Adapter

ADSI
Client

DCOM

WMI
WMICIM
CIMManagement
ManagementSchema
Schema
Schema RT
Schema
RT
/ /Provider
Provider
Subsystem
Subsystem

Query
Query
Service
Service

View
View
Service
Service

WMI
WMIServices
Services

Pub/Sub
Pub/Sub
Service
Service

DCOM

Event
Event
Filtering
Filtering

WMI Repository

WMI Providers (loaded on demand)


Registry
Registry

Perf
Perf
Counters
Counters

Windows
Windows NT
NT
Event
Log
Event Log

WMI
WMI ext
ext
for
for WDM
WDM

SNMP
SNMP

Active
Active
Directory
Directory

10

Windows XP Professional and


.NET Server implementation

WMIC is an admin tool


WMIC includes 80 aliases
(FriendlyCommandNames):

Supporting about 150 methods


Exposing thousands of properties
Providing reporting ability in TXT, HTML, XML,
MOF, CSV, or any proprietary format

It allows access to any CIM-like schema


object (greater than 10 KB in the box)
11

WMIC: Two Modes of Operation


c:\>wmic process list brief

wmic:root\cli>/?

12

WMIC Architecture
Alias
Alias

(FriendlyName
(FriendlyName))
Definitions
Definitions

Alias
Alias

Schema
Schema

Two ways of using:


- C:\> wmic process
- wmic:root\cli> process

(scripting/batch mode)
(interactive mode)

Examples of interactive mode:


> OS get name, locale, bootdevice
> OS where name='sun' call shutdown
> /node:@MyOrg os get /all /format:htable

WMIC
Engine

Provider
Provider
Provider
Provider
Provider

WMI
WMI

Console

XML
XML
DOM
DOM

XSLT
XSLT
XSLT
XSLT
XSLT
XSLT

HTML
CSV
MOF
Customer defined

13

Principles

Generic command-line tool:

Progressive help discovery


Total partitioning between:

Driven by instrumentation
Uses common grammar
Provides transparent remoting

Aliases
Parser/engine
Transforms

Role based management:

Operating against various folders (namespaces)


Operating against single and multiple computers
Operated by functional teams

14

WMIC Abilities

Define aliases, add output formats, and


create and run scripts
Browse the WMI schema, and query its
classes and instances
Get information from a local computer, a
remote computer, and from multiple
computers in a single command

15

Scenarios

Manage a local or remote computer

Remotely manage multiple computers

Telnet

to a remote computer and run tools

Use scripting to automate management

16

WMIC in Enterprise

Management
Station
(Windows XP Professional
or. NET Server)

Network

Target 1

Target 3

(WMI Installed)

(MOM Server)

Target 2

(SMS Server)

17

Examples of Using WMIC


and Its Aliases

18

Getting Started Default Settings

19

Getting Started Context

20

Getting Started Aliases

21

Using Progressive Discovery Help

22

Using Verbs

23

Using Formats

24

Remoting

25

Examples of Commands
QFE
PRODUCT or

PRODUCT list brief or PRODUCT list full

cpu get MaxClockSpeedList


Process Where Description="WinLogon.exe" Get VirtualSize /EVERY:5
SERVICE WHERE CAPTION='TELNET' CALL STARTSERVICE
NICCONFIG WHERE index=1 CALL EnableStatic ("10.0.0.2"),("255.0.0.0")
NICCONFIG WHERE index=1 CALL SetGateways ("10.0.0.8","10.0.0.9"),(1,2)
/NODE:@"c:\MyServerList.txt" OS WHERE (Primary="TRUE" and
Organization!="Organization1") CALL Win32ShutDown 6
26

Some Useful Tips

NamedParameters or WHERE clause for large datasets:

WMIC ALIAS OS or WMIC ALIAS OS LIST BRIEF


WMIC USERACCOUNT WHERE "Name='PutUserNameHere' and Domain='PutDomainNameHere'"
WMIC FCDIR WHERE Name='c:\\WINDOWS or WMIC FSDIR C:\\windows
WMIC DATAFILE WHERE "PATH='\\windows\\' and Extension='exe' and FileSize>'108032'" GET
LastAccessed, LastModified, Name, FileSize
WMIC NTEVENT WHERE "LogFile='system' and Type>'0'" GET Message, TimeGenerated

Use "" to separate "WHERE" expression instead of () :

WMIC NTEVENT WHERE "LogFile='system' and Type>'4'"


Opposite to: WMIC NTEVENT WHERE (LogFile='system' and TYPE>4)
Shell will misinterpret >4) and will try to redirect output to file named 4)
27

Advanced Applications

WMIC brings the end-to-end capability to the


management infrastructure:

The application developer adds instrumentation*,


and command access immediately becomes
available at no additional cost.
With little additional investment in defining the
alias, the developer can simplify most of the
common command (cmd) operations.

* This is simplified in Microsoft .NET Framework (versus .NET)

28

Direct
DirectAccess:
Access:
PATH/CLASS
PATH/CLASS
commands
commands

Supporting Instrumentation
> PATH <ClassName> [verb] [properties] [format] query Instances of a Class
Example: > path win32_process get name, processid, handle
> /node:@list.txt path HardwareConfig call DriverUpdate
> CLASS <ClassName> [verb] [properties] [format] query Class properties
Example: > wmic class win32_share >ShareSchema.html

Provider
Provider
Provider

Any
AnyWMI
WMI
Schema
Schema

WMIC
Engine

Console

XML
XML
DOM
DOM

XSLT
XSLT
XSLT
XSLT
XSLT
XSLT

HTML
CSV
MOF
Customer defined

29

Examples of Using WMIC to


Directly Access
Instrumented Data

30

Using the PATH Command

31

Using the CLASS Command

32

Automating WMIC
New

customization and development

Aliases, MOFs, view provider,


Through

application

Batch files, scripting,

Example:
WMIC /NODE:@"c:\MyServerList.txt" SERVICE WHERE caption=
"SSDP Discovery Service" CALL ChangeStartMode "Disabled"
MyServerList.txt

Server1
Server1 Server6
Server6
Server2
Server7
Server2 Server7
Server3
Server3 Server8
Server8
Server4
Server9
Server4 Server9
Server5
Server5 .
.

.
.
.
.
.
.
.
.
Server1024
Server1024

33

How You Can Extend WMIC

Customize existing aliases and


properties
Define new aliases
Add output formats (*.xsl)
Create new transforms
Create and run scripts
Browse a schema and query its
classes and instances
34

Creating and Editing Aliases

Access files:
CliAliases.mof Alias class and namespace
definitions
CliEgAliases.mof Aliases instances
CliEgAliases.mfl Aliases localization

Add and edit instances in CliEgAliases.mof


Copy aliases friendly names and
descriptions to CliEgAliases.mfl
Mofcomp the files

35

Examples of Customization

Defining and editing aliases (friendly names) or


property names

instance of MSFT_CliAlias
{
Connection =
.........................................
Description = "Basic input/output services (BIOS) management.";
Formats =
........................................................................
FriendlyName = "BIOS";
..................................................
Target = "Select * from Win32_BIOS";
};
instance of MSFT_LocalizablePropertyValue
{
RelPath = "MSFT_CliAlias.FriendlyName=\" BIOS\"";
PropertyName = "Description";
Text = {"Basic input/output services (BIOS) management."};
};

36

Examples of Customization (2)

Defining a new transform:


instance of MSFT_CliTranslateTable
{
Name = "BasicXml";
Tbl =
{
Instance of MSFT_CliTranslateTableEntry
{
FromValue = "&gt;";
ToValue = ">";
},
Instance of MSFT_CliTranslateTableEntry
{
FromValue = "&lt;";
ToValue = "<";
}
};
};

37

Examples of Customization (3)

Defining and adding new formats:

Xsl-mappings.xml
<XSLMAPPINGS>
<XSLFORMAT KEYWORD="TABLE">texttable.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="VALUE">textvalueList.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="LIST">textvalueList.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="RAWXML">rawxml.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="HTABLE">htable.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="HFORM">hform.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="HXML">xml.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="HMOF">mof.xsl</XSLFORMAT>
<XSLFORMAT KEYWORD="CSV">csv.xsl</XSLFORMAT>
</XSLMAPPINGS>

38

Examples of Customization (4)

Reporting:

C:\>wmic ntevent where "eventtype<3 and logfile='Application'" get logfile,


SourceName, eventtype, TimeGenerated
/format:htable:"datatype=number":"sortby=EventType" > c:\applicationLog.htm
C:\>applicationLog.htm

Additional Information Sources


for WMI

WMI articles on the MSDN Web site at


http://msdn.microsoft.com /
Send e-mail to wmi@microsoft.com
Several books about WMI are available
Help and Support Center

40

Thank you for joining todays Microsoft Support


WebCast.
For information about all upcoming Support WebCasts,
and access to the archived content (streaming media
files, PowerPoint slides, and transcripts), please visit:
http://support.microsoft.com/webcasts/
Your feedback is sincerely appreciated. Please send any
comments or suggestions about the Support
WebCasts to supweb@microsoft.com.

Vous aimerez peut-être aussi