More and more with management packs   Leave a comment

I’ve been a little slow in updating here, but that doesn’t reflect any inactivity, just my poor rhythm for posting.

Earlier in the year I did a post on what was possible to do in a single line of PowerShell. In this post, I’m going to take that further and explore this in more detail. Specifically, we’ll take a closer look at all of the possibilities with PowerShell and Service Manager management packs. I’ve blogged on management packs in the past, but generally on what to do with them rather than what they are. In this blog, we’ll take a look at the various properties of a management pack and how easy they are to access from PowerShell.

First, if we take a look at the available properties of a management pack, we see a pretty rich object model.

PS> $emg = new-object Microsoft.EnterpriseManagement.EnterpriseManagementGroup Localhost
PS> $emg.ManagementPacks.GetManagementPacks()|get-member


   TypeName: Microsoft.EnterpriseManagement.Configuration.ManagementPack

Name                                        MemberType Definition
----                                        ---------- ----------
AcceptChanges                               Method     System.Void AcceptChanges(), System.Void AcceptChanges(Micros...
AddService                                  Method     System.Void AddService[T, V](string name, Microsoft.Enterpris...
CheckVersionCompatibility                   Method     System.Void CheckVersionCompatibility(Microsoft.EnterpriseMan...
Configure                                   Method     System.Void Configure(System.IO.Stream configuration)
DeleteEnterpriseManagementObjectGroup       Method     System.Void DeleteEnterpriseManagementObjectGroup(Microsoft.E...
DeleteMonitoringObjectGroup                 Method     System.Void DeleteMonitoringObjectGroup(Microsoft.EnterpriseM...
Dispose                                     Method     System.Void Dispose()
Equals                                      Method     bool Equals(System.Object obj)
FindManagementPackElementByName             Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackEl...
GetCategories                               Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackEl...
. . .
RemoveService                               Method     System.Void RemoveService(string name)
RemoveServices                              Method     System.Void RemoveServices()
ToString                                    Method     string ToString()
Verify                                      Method     System.Void Verify()
ContentReadable                             Property   System.Boolean ContentReadable {get;}
DefaultLanguageCode                         Property   System.String DefaultLanguageCode {get;set;}
Description                                 Property   System.String Description {get;set;}
DisplayName                                 Property   System.String DisplayName {get;set;}
. . .
SchemaVersion                               Property   System.Version SchemaVersion {get;}
Sealed                                      Property   System.Boolean Sealed {get;}
TimeCreated                                 Property   System.DateTime TimeCreated {get;}
Version                                     Property   System.Version Version {get;set;}
VersionId                                   Property   System.Guid VersionId {get;}

In fact, you’ll see about 150 different methods and properties. I’ve discussed various aspects of some of the properties and methods in earlier posts, but I want to concentrate on the methods in this posting, and the methods I want to look at specifically are the Get* methods. These methods return information about the contents and configuration of the management packs. Since there are about 100 Get* methods, i’d like to reduce the list to something more manageable, so we’ll only look at the get* methods that don’t take any arguments.

PS> $emg.ManagementPacks.GetManagementPacks()|get-member get*|?{$_.definition -match "\(\)"}


   TypeName: Microsoft.EnterpriseManagement.Configuration.ManagementPack

Name                        MemberType Definition
----                        ---------- ----------
GetCategories               Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetClasses                  Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetConfigurationGroups      Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetConsoleTasks             Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetDataTypes                Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetDataWarehouseDataSets    Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetDataWarehouseScripts     Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetDiagnostics              Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetDimensionTypes           Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetDiscoveries              Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetEnumerations             Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetFactTypes                Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetFolderItems              Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackItemCollection[Mic...
GetFolders                  Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetForms                    Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetHashCode                 Method     int GetHashCode()
GetImageReferences          Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackItemCollection[Mic...
GetImages                   Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetLanguagePacks            Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetLinkedReports            Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetManagementPackCategories Method     System.Collections.Generic.IList[Microsoft.EnterpriseManagement.Configuration...
GetMeasureTypes             Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetModuleTypes              Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetMonitors                 Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetObjectTemplates          Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetOutriggerTypes           Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetOverrides                Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetRecoveries               Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetRelationshipFactTypes    Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetRelationships            Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetReportParameterControls  Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetReportResources          Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetReports                  Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetResources                Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetRules                    Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetSchemaTypes              Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetSecureReferences         Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetServiceLevelObjectives   Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetServices                 Method     System.Collections.Generic.IList[T] GetServices[T]()
GetStringResources          Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetTasks                    Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetTemplates                Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetType                     Method     type GetType()
GetTypeProjections          Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetUIPages                  Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetUIPageSets               Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetUnitMonitorTypes         Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetViews                    Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetViewTypes                Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...
GetWarehouseModuleTypes     Method     Microsoft.EnterpriseManagement.Configuration.ManagementPackElementCollection[...

There are still 50 of these, but there are some methods that are easier to use. First nearly all of these methods return a ManagementPackElementCollection, only 2 return a ManagementPackItemCollection (GetFolderItems and GetImageReferences), and 4 others require a typed invocation (GetServices, GetManagementPackCategories, GetResources and GetServiceLevelObjectives). We’ll focus on the methods that return a ManagementPackElementCollection and that don’t take a generic type, because they’re the simplest to deal with. Since these methods don’t take any arguments, we can just call them and see what we get back. The method name should give us a clue about what we’ll get back, and you can check the Service Manager SDK documentation as well for more information.

As a first example, we’ll retrieve the System.Library management pack and inspect all the classes declared in the mp and get their  base class.

PS> $emg.ManagementPacks.GetManagementPacks()|?{$_.Name -eq "System.Library"}|
>> %{$_.GetClasses()}|ft Abstract,Name,@{Label="Base";e={$emg.entitytypes.GetClass($_.base.id).Name}} -au
>>

Abstract Name                        Base
-------- ----                        ----
    True System.Entity
    True System.Collections          System.Entity
    True System.ConfigItem           System.Entity
    True System.LogicalEntity        System.ConfigItem
    True System.ApplicationComponent System.LogicalEntity
    True System.ComputerRole         System.LogicalEntity
    True System.Database             System.ApplicationComponent
    True System.Device               System.LogicalEntity
    True System.Computer             System.Device
    True System.FTPSite              System.ApplicationComponent
    True System.Group                System.LogicalEntity
    True System.LocalApplication     System.LogicalEntity
    True System.LogicalHardware      System.LogicalEntity
    True System.NetworkDevice        System.Device
    True System.OperatingSystem      System.LogicalEntity
    True System.Perspective          System.LogicalEntity
    True System.PhysicalEntity       System.ConfigItem
    True System.Printer              System.Device
    True System.Service              System.LogicalEntity
    True System.SoftwareInstallation System.LogicalEntity
    True System.User                 System.LogicalEntity
   False System.Domain.User          System.User
    True System.WebSite              System.ApplicationComponent

Note that I’m using the EMG in the formatting directives to get the base class.

If we wanted to get the XML for one of these classes, we can do that with the CreateNavigator method.  We’ll collect the classes and then use the CreateNavigator method to get at the XML. This examples retrieves the System.Library management pack and then displays the XML for the System.ConfigItem class.

PS> $emg.ManagementPacks.GetManagementPacks()|?{$_.Name -eq "System.Library"}|
>> %{$_.GetClasses()}|?{$_.Name -eq "System.ConfigItem"}|%{$_.CreateNavigator().OuterXML}
>>
<ClassType ID="System.ConfigItem" Accessibility="Public" Abstract="true" 
        Base="System.Entity" Hosted="false" Singleton="false" Extension="false">
  <Property ID="ObjectStatus" Type="enum" AutoIncrement="false" Key="false" CaseSensitive="false" 
        MaxLength="256" MinLength="0" Required="false" EnumType="System.ConfigItem.ObjectStatusEnum" 
        DefaultValue="System.ConfigItem.ObjectStatusEnum.Active" />
  <Property ID="AssetStatus" Type="enum" AutoIncrement="false" Key="false" CaseSensitive="false" 
        MaxLength="256" MinLength="0" Required="false" EnumType="System.ConfigItem.AssetStatusEnum" />
  <Property ID="Notes" Type="richtext" AutoIncrement="false" Key="false" CaseSensitive="false" 
        MaxLength="4000" MinLength="0" Required="false" />
</ClassType>

Pretty cool! The following example retrieves all the views in the system:

PS> $emg.ManagementPacks.GetManagementPacks()|%{$_.GetViews()}|ft name,description

Name                                                        Description
----                                                        -----------
Microsoft.EnterpriseManagement.ServiceManager.UI.Adminis... Lists all subscriptions
Microsoft.EnterpriseManagement.ServiceManager.UI.Adminis... Lists all Run As accounts
Microsoft.EnterpriseManagement.ServiceManager.UI.Adminis... Contains general, portal, and solution settings
Microsoft.EnterpriseManagement.ServiceManager.UI.Adminis... Administration Overview
Microsoft.EnterpriseManagement.ServiceManager.UI.Adminis... Lists all templates
. . .
AllComputersView                                            Lists all computers
AllPrintersView                                             Lists all printers
QueuesView                                                  Lists all the queues available
TemplatesView                                               Lists all the templates available
TasksView                                                   Lists all the console tasks defined in the system
EnumerationView                                             Displays all the lists available
GroupsView                                                  Lists all groups
WorkItemExclusionRule                                       Work item exclusion workflow view
ChangeManagement.Views.ChangeRequestsCancelled              Lists all canceled change requests
ChangeManagement.Views.ChangeRequestsCompleted              Lists all completed change requests
ChangeManagement.Views.ChangeRequestsClosed                 Lists all closed change requests
ChangeManagement.Views.AllChangeRequests                    Lists all change requests
ChangeManagement.Views.ChangeRequestsRejected               Lists all rejected change requests
ChangeManagement.Views.ChangeRequestsInReview               Change Requests: In Review
. . .
System.WorkItem.Incident.Pending.View                       Lists all pending incidents
System.WorkItem.Incident.OverDue.View                       Lists all overdue incidents
System.WorkItem.Incident.Active.Unassigned.View             Lists all open unassigned incidents
Microsoft.SystemCenter.AllActiveAnnouncementsView           Active Announcements
Microsoft.SystemCenter.AllAnnouncementsView                 All Announcements

And we can inspect the XML for the one of the views (say the AllPrintersView), with this one-liner:

PS> $emg.ManagementPacks.GetManagementPacks()|%{$_.GetViews()}|
>> ?{$_.name -eq "allprintersview"}| %{$_.createnavigator().outerxml}

<View ID="AllPrintersView" Accessibility="Public" Enabled="true" Target="Windows!Microsoft.AD.Printer" TypeID="SMConsole!GridViewType" Visible="true">
  <Category>NotUsed</Category>
  <Data>
    <Adapters>
      <Adapter AdapterName="dataportal:EnterpriseManagementObjectProjectionAdapter">
        <AdapterAssembly>Microsoft.EnterpriseManagement.UI.SdkDataAccess</AdapterAssembly>
        <AdapterType>Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.EnterpriseManagementObjectProjectionAdapter</AdapterType>
      </Adapter>
      <Adapter AdapterName="viewframework://Adapters/AdvancedList">
        <AdapterAssembly>Microsoft.EnterpriseManagement.UI.ViewFramework</AdapterAssembly>
        <AdapterType>Microsoft.EnterpriseManagement.UI.ViewFramework.AdvancedListSupportAdapter</AdapterType>
      </Adapter>
      <Adapter AdapterName="omsdk://Adapters/Criteria">
        <AdapterAssembly>Microsoft.EnterpriseManagement.UI.SdkDataAccess</AdapterAssembly>
        <AdapterType>Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.SdkCriteriaAdapter</AdapterType>
      </Adapter>
    </Adapters>
    <ItemsSource>
      <AdvancedListSupportClass DataTypeName="" AdapterName="viewframework://Adapters/AdvancedList" FullUpdateAdapter="dataportal:EnterpriseManagementObjectProjectionAdapter" DataSource="mom:ManagementGroup" IsRecurring="True" RecurrenceFrequency="{x:Static s:Int32.MaxValue}" FullUpdateFrequency="1" Streaming="true" xmlns="clr-namespace:Microsoft.EnterpriseManagement.UI.ViewFramework;assembly=Microsoft.EnterpriseManagement.UI.ViewFramework" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib">
        <AdvancedListSupportClass.Parameters>
          <QueryParameter Parameter="TypeProjectionName" Value="Microsoft.Windows.PrinterView.ProjectionType" />
        </AdvancedListSupportClass.Parameters>
      </AdvancedListSupportClass>
    </ItemsSource>
    <Criteria>
      <QueryCriteria Adapter="omsdk://Adapters/Criteria" xmlns="http://tempuri.org/Criteria.xsd">
        <Criteria>
          <FreeformCriteria>
            <Freeform>
              <Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
                <Expression>
                  <SimpleExpression>
                    <ValueExpressionLeft>
                      <Property>$Context/Property[Type='System!System.ConfigItem']/ObjectStatus$</Property>
                    </ValueExpressionLeft>
                    <Operator>NotEqual</Operator>
                    <ValueExpressionRight>
                      <Value>$MPElement[Name="System!System.ConfigItem.ObjectStatusEnum.PendingDelete"]$</Value>
                    </ValueExpressionRight>
                  </SimpleExpression>
                </Expression>
              </Criteria>
            </Freeform>
          </FreeformCriteria>
        </Criteria>
      </QueryCriteria>
    </Criteria>
  </Data>
  <Presentation>
    <Columns>
      <mux:ColumnCollection xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mux="http://schemas.microsoft.com/SystemCenter/Common/UI/Views/GridView" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:datebinding="clr-namespace:Microsoft.EnterpriseManagement.UI.SdkDataAccess.Common;assembly=Microsoft.EnterpriseManagement.UI.SdkDataAccess">
        <mux:Column Name="uncName" DisplayMemberBinding="{Binding Path=UNCName}" Width="120" DisplayName="Header_UNCName" Property="UNCName" DataType="s:String" />
        <mux:Column Name="printerName" DisplayMemberBinding="{Binding Path=PrinterName}" Width="120" DisplayName="Header_PrinterName" Property="PrinterName" DataType="s:String" />
        <mux:Column Name="description" DisplayMemberBinding="{Binding Path=Description}" Width="120" DisplayName="Header_Description" Property="Description" DataType="s:String" />
        <mux:Column Name="location" DisplayMemberBinding="{Binding Path=Location}" Width="120" DisplayName="Header_Location" Property="Location" DataType="s:String" />
      </mux:ColumnCollection>
    </Columns>
    <ViewStrings>
      <ViewString ID="Header_UNCName">$MPElement[Name="AllPrintersView.Header_UNCName"]$</ViewString>
      <ViewString ID="Header_PrinterName">$MPElement[Name="AllPrintersView.Header_PrinterName"]$</ViewString>
      <ViewString ID="Header_Description">$MPElement[Name="AllPrintersView.Header_Description"]$</ViewString>
      <ViewString ID="Header_Location">$MPElement[Name="AllPrintersView.Header_Location"]$</ViewString>
    </ViewStrings>
  </Presentation>
</View>

Since the CreateNavigator method is available on ManagementPackElement, we can use that method with every one of the objects returned by the methods mentioned above – it’s a great way to explore and see what’s going on in your management pack.

As an interesting aside, we can invoke all of these simple methods with a couple of lines of script. This will tell us the total number of each of the management pack elements returned by the method. The first line collects the names of the methods that we want to invoke. The second line creates a hash table to hold our results and the last line retrieves all the management packs, and invokes each method on the management pack object and adds the count of those elements to the hash table. This is a pretty cool trick to invoke a method without know what the method name is before hand.

PS> $names = $emg.ManagementPacks.GetManagementPacks()|
>> get-member get*s|
>> ?{$_.definition -match "ManagementPackElementCollection" -and 
>> $_.definition -notmatch "\[T\]"}|%{$_.name}
PS> $counthash = $names | %{ $h = @{}}{$h.$_ = 0 } {$h }
PS> $emg.ManagementPacks.GetManagementPacks()|%{
>> $mp = $_
>> $names | %{ $counthash.$_ += $mp.$_.invoke().count }
>> }
>>
PS> $counthash

Name                           Value
----                           -----
GetReportResources             28
GetModuleTypes                 293
GetObjectTemplates             24
GetUIPages                     48
GetOutriggerTypes              30
GetRules                       53
GetTasks                       6
GetReports                     23
GetSchemaTypes                 28
GetClasses                     272
GetMonitors                    47
GetTypeProjections             56
GetReportParameterControls     0
GetConfigurationGroups         0
GetDimensionTypes              26
GetRelationships               124
GetViewTypes                   24
GetLinkedReports               0
GetStringResources             1211
GetFactTypes                   4
GetDataTypes                   45
GetTemplates                   3
GetForms                       16
GetFolders                     85
GetWarehouseModuleTypes        9
GetMeasureTypes                2
GetSecureReferences            11
GetRecoveries                  1
GetViews                       138
GetDiscoveries                 31
GetUIPageSets                  225
GetEnumerations                460
GetDataWarehouseScripts        38
GetConsoleTasks                160
GetCategories                  583
GetDataWarehouseDataSets       0
GetOverrides                   49
GetImages                      254
GetDiagnostics                 0
GetLanguagePacks               89
GetRelationshipFactTypes       28
GetUnitMonitorTypes            239

woo hoo!

Advertisements

Posted May 28, 2010 by jtruher3 in ServiceManager

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: