MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer...

28
MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation

description

Windows Management Instrumentation (WMI) Microsoft’s implementation of WBEM Uniform access to management information Most Exchange 2003 monitoring is done through WMI

Transcript of MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer...

Page 1: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

MSG 334Creating Exchange Administrative Scripting for the Non-Programmer Susan HillLead Programmer WriterMicrosoft Corporation

Page 2: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Agenda

Overview of WMIArchitectureKey Features

Code SamplesWMI in Exchange Server 2003

Page 3: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Windows Management Instrumentation (WMI)

Microsoft’s implementation of WBEM Uniform access to management information Most Exchange 2003 monitoring is done through WMI

Page 4: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Overview Of WMI

Based on Distributed Management Task Force Standards – CIM, WBEM Designed to reduce TCO of Windows Systems Extensible, object-oriented APIEnables system-wide and application-level observation and control

Consistent schema, queries, methods, events, and API

Page 5: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

WMI Architecture

WMIWMI

ConsumersConsumers

RegistryRegistry PerformancePerformanceCountersCounters

Other WMI Other WMI ProvidersProvidersExchangeExchange DirectoryDirectory

Windows Windows Management Management

InstrumentationInstrumentationServiceService

Page 6: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

How WMI Works in Exchange 2003 Server

Consumer calls a WMI serviceService authenticates the clientService passes call to the Exchange providerProvider queries the system for the information Provider returns information back to client

Page 7: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Key Features of WMI

API accessible from multiple programming languagesRemote administration Discoverability and navigation Query capability Event publication and subscription

Page 8: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Multiple Languages

C++Visual BasicJScriptVBScriptC#Perl …

Page 9: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Remote Administration

No different than local administrationAllows for enterprise management from a single computer

Page 10: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Discoverability and Navigation

Enumerate Classes Tells you what objects are available

Associations Define the relationships between classes Can be traversed

Page 11: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Query Capability

Data is stored in a relational database WQL – SQL-style language

Select * from ExchangeServerState where ServerState=3

Page 12: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Eventing

Clients subscribe for events No internal event mechanism needed Events can be “keyed” off of:

Instance Creation, Modification, Deletion

Page 13: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

What’s New in WMI for Exchange 2003

20 new classesMessage TrackingQueue ManagementPublic Folder ManagementMailbox MAPI Table Management

Full list in the Exchange 2003 SDK on MSDN

Page 14: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Skeleton of a WMI program

Get the WMI locator objectGain the root interface

microsoftexchangev2Query the provider

Can use WSQL

Interpret your results

Page 15: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

VBS – Public Folder Names

Set oLocator = CreateObject("WbemScripting.SWbemLocator")

Set oServices = oLocator.connectServer("localhost", "root\microsoftexchangev2")

Set oPFs = oServices.ExecQuery("select * from exchange_publicfolder”)

For each oPF in oPFsWScript.Echo(oPF.name)

Next

Page 16: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

VBS – Create Public FolderSet oLocator = CreateObject("WbemScripting.SWbemLocator")Set oServices = oLocator.connectServer("localhost", "root\microsoftexchangev2")

'get the mapi folder treeset oTLHs = oServices.ExecQuery("select * from exchange_foldertree where

mapifoldertree = true")

for each oTLH in oTLHs'there is only one mapi TLHszRootFolderUrl = oTLH.RootFolderUrl

next

'create a public folder under the mapi folder treeSet oPF = oServices.Get("Exchange_PublicFolder").SpawnInstance_()oPF.Name = "WMI Public Folder"oPF.ParentFriendlyUrl = szRootFolderUrloPF.Put_

wscript.echo("done.")

Page 17: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

VBS – Mailbox TableSet oLocator = CreateObject("WbemScripting.SWbemLocator")Set oServices = oLocator.connectServer("localhost", "root\

microsoftexchangev2")

set oLogins = oServices.ExecQuery("select * from Exchange_Logon")

for each oLogin in oLogins WScript.Echo(oLogin.LoggedOnUserAccount & " " & oLogin.ClientVersion)

Next

wscript.echo("done.")

Page 18: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

VBS Programs Calling VBS Programs Calling WMIWMI

demodemo

Page 19: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

JScript – Message Trackingvar oLocator = new ActiveXObject("WbemScripting.SWbemLocator");

var oServices = oLocator.connectServer("", "root\\microsoftexchangev2");

var szQuery = "select * from exchange_messagetrackingentry";

var e = new Enumerator(oServices.ExecQuery(szQuery));

var oMT = e.item();

var e = new Enumerator(oMT.Properties_);

for (; !e.atEnd(); e.moveNext())WScript.Echo (e.item().Name + " = " + e.item().Value);

Page 20: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

JScript Program Calling JScript Program Calling WMIWMI

demodemo

Page 21: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

C# Get Exchange DCpublic class WMICommon{

public WMICommon(){}~WMICommon(){}

public string GetDC(){ ManagementObjectSearcher searcher = new ManagementObjectSearcher(); string DCName = "";

ManagementScope scope = new ManagementScope("root\\microsoftexchangev2"); System.Management.ObjectQuery query = new System.Management.ObjectQuery("select *

from Exchange_DSAccessDC whereType = 0"); searcher.Scope = scope; searcher.Query = query;

foreach (ManagementObject configDC in searcher.Get()) { DCName = configDC["Name"].ToString(); }

searcher.Dispose();}

return DCName;

Page 22: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

C# Program Calling WMIC# Program Calling WMI

demodemo

Page 23: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Additional Information

Good WMI Intro Article http://msdn.microsoft.com/library/techart/mngwmi.htm

Exchange Server 2003 WMIExchange Server 2003 SDK Documentationhttp://msdn.microsoft.com/exchange

Page 24: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Ask The ExpertsGet Your Questions Answered

11:00 Friday morning

Page 25: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Community Resources

Community Resourceshttp://www.microsoft.com/communities/default.mspx

Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/

NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx

User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx

Page 26: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

Suggested Reading And Resources

The tools you need to put technology to work!The tools you need to put technology to work!

TITLETITLE AvailableAvailable

Microsoft® Exchange Server 2003 Microsoft® Exchange Server 2003 Administrator's Companion:Administrator's Companion:0-7356-1979-40-7356-1979-4 9/24/039/24/03

Active Directory® for Microsoft® Active Directory® for Microsoft® Windows® Server 2003 Windows® Server 2003 Technical Reference:Technical Reference:0-7356-1577-20-7356-1577-2

TodayToday

Microsoft Press books are 20% off at the TechEd Bookstore

Also buy any TWO Microsoft Press books and get a FREE T-Shirt

Page 27: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

evaluationsevaluations

Page 28: MSG 334 Creating Exchange Administrative Scripting for the Non-Programmer Susan Hill Lead Programmer Writer Microsoft Corporation.

© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.