How to Export an Operations Manager Management Pack

System Center

Updated: May 22, 2009

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

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.


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.ObjectModel;
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);
            ReadOnlyCollection<ManagementPack> mpCollection = 
            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);

See Also