OK, great job! You've figured out how to extend classes. Now, how do you programmatically access them? I wrote up this quick example to show you how you can extend the Microsoft.Windows.Computer class with a couple of properties and then create an object of that class and populate the values of those properties.

Here we go! First a simple management pack to extend the Microsoft.Windows.Computer class:

<ManagementPack ContentReadable="true" SchemaVersion="1.1"

    xmlns:xsd="http://www.w3.org/2001/XMLSchema"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <Manifest>

        <Identity>

            <ID>TestMP</ID>

            <Version>1.0.0.0</Version>

        </Identity>

        <Name>Configuration Items Extension</Name>

        <References>

            <Reference Alias="WinLib">

                <ID>Microsoft.Windows.Library</ID>

                <Version>1.0.3113.0</Version>

                <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

            </Reference>

        </References>

    </Manifest>

    <TypeDefinitions>

        <EntityTypes>

            <ClassTypes>

                <ClassType ID="TestMP.ExtensionClass" Accessibility="Public" Base="WinLib!Microsoft.Windows.Computer" Extension="true">

                    <Property ID="MySerialNumber" Type="string" />

                    <Property ID="MyAssetTag" Type="string" />

                </ClassType>

            </ClassTypes>

        </EntityTypes>

    </TypeDefinitions>

<LanguagePacks>

<LanguagePack ID="ENU" IsDefault="true">

<DisplayStrings>

<DisplayString ElementID="TestMP.ExtensionClass" SubElementID="MySerialNumber">

<Name>MySerialNumber</Name>

</DisplayString>

<DisplayString ElementID="TestMP.ExtensionClass" SubElementID="MyAssetTag">

<Name>MyAssetTag</Name>

</DisplayString>

</DisplayStrings>

</LanguagePack>

</LanguagePacks>

</ManagementPack>

 

Next – here is a simple console application that creates a new object of that class:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.EnterpriseManagement;

using Microsoft.EnterpriseManagement.Common;

using Microsoft.EnterpriseManagement.Configuration;

 

namespace CreateServer

{

class Program

{

static void Main(string[] args)

{

EnterpriseManagementGroup emg = new EnterpriseManagementGroup("localhost");

ManagementPackClass clsWindowsComputer = emg.EntityTypes.GetClass(new Guid("EA99500D-8D52-FC52-B5A5-10DCD1E9D2BD")); //This GUID represents the Microsoft.Windows.Windows.Computer class

ManagementPackClass clsWindowsComputerExtension = emg.EntityTypes.GetClass(new Guid("35097F79-9E81-AB9C-8553-81D71243D9DA")); //This GUID represents the TestMP.ExtensionClass class

EnterpriseManagementObjectProjection emopServer = new EnterpriseManagementObjectProjection(emg, clsWindowsComputer);

emopServer.Object[clsWindowsComputer, "PrincipalName"].Value = "mycomputer.mycompany.com"; //This is the key property and must be set

emopServer.Object[clsWindowsComputerExtension, "MySerialNumber"].Value = "123";

emopServer.Object[clsWindowsComputerExtension, "MyAssetTag"].Value = "456";

emopServer.Commit();

}

}

}

 

That's it!   Import your MP, run your command line application and now you’ll have a computer in the UI that looks like this:

image

The key here is to use your extended class ID when getting/setting the extended class properties.

Source files are available here: http://cid-17faa48294add53f.skydrive.live.com/self.aspx/.Public/CreateServer.zip