次の方法で共有


How to Export a Management Pack

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

You can use the Operations Manager class libraries to perform management pack deployment tasks. For example, you can export an existing management pack to an XML file.

Example

The following example demonstrates how to export the contents of a management pack to an XML file:

/// <summary>
/// Exports a sample Management Pack whose display name is
/// "Test Management Pack 1".
/// </summary>
using System;
using System.Collections.Generic;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;
using System.IO;
using System.Text;
using System.Xml;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementGroup mg = new ManagementGroup("localhost");

            // Define the path to the directory that will store
            // the exported Management Pack.
            string mpPath = @"C:\Program Files\System Center Management Packs\";

            string query = "DisplayName = 'Test Management Pack 1'";
            ManagementPackCriteria mpCriteria = new ManagementPackCriteria(query);
            IList<ManagementPack> mpCollection = 
                mg.ManagementPacks.GetManagementPacks(mpCriteria);
            if (mpCollection.Count != 1)
                throw new InvalidOperationException(
                    "Error! Expected one Management Pack with: " + query);
            
            string outputFileName = mpPath + mpCollection[0].Name + ".xml";
            using (Stream mpStream = new FileStream(outputFileName, FileMode.Create))
            {
                XmlWriter xmlwriter = XmlWriter.Create(mpStream);
                ManagementPackXmlWriter mpwriter = new ManagementPackXmlWriter(xmlwriter);
                mpwriter.WriteManagementPack(mpCollection[0]);
                mpStream.Close();
            }
        }
    }
}

See Also

Tasks

How to Import a New Management Pack
How to Display Management Pack Contents
How to Remove an Existing Management Pack

Other Resources

Automating Management Pack Development