How to Export a Management Pack

Updated: January 31, 2012

Applies To: System Center 2012 - Operations Manager

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.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 = 
			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