Importing Management Packs Programmatically (and How to Connect to a Management Server in an Untrusted Domain)

Importing Management Packs Programmatically (and How to Connect to a Management Server in an Untrusted Domain)

  • Comments 2
  • Likes

You can import MPs using the PowerShell cmdlet Import-SCSMManagementPack.  That works for .xml, .mp, or .mpb files.  But what if you wanted to do it programmatically using the SDK?  No problem.  You just need to know how to do it.

Here is some sample code to show you how it’s done.  As a bonus you can see in this code sample how to Connect As some particular account so that you can programmatically connect to SCSM as a different account.  This is good for untrusted domain configurations where you need to connect using an IP address.  Note how you need to import management pack bundles (.mpb) differently than you do a .xml or a .mp file.

                EnterpriseManagementConnectionSettings cs = new EnterpriseManagementConnectionSettings("192.168.1.100");
                cs.Domain = "fabrikam";
                cs.UserName = "administrator";
                char[] charPassword = { 'S', 'M', 'X','#','2','0','0','1' };
                System.Security.SecureString ssPassword = new System.Security.SecureString();
                foreach (char c in charPassword)
                    ssPassword.AppendChar(c);
                cs.Password = ssPassword;

                EnterpriseManagementGroup emg = new EnterpriseManagementGroup(cs);

                //Import XML or .mp:
                ManagementPack managementPack = new ManagementPack("C:\\Temp\\Microsoft.SystemCenter.DataWarehouse.Library.mp");
                emg.ManagementPacks.ImportManagementPack(managementPack);

                //Import MPB:
                ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
                ManagementPackBundle bundle = reader.Read("MyMP.mpb",emg);
                emg.ManagementPacks.ImportBundle(bundle);
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Thanks for the sample Travis.

    I can confirm that this works very well now. ;-)

  • I am Importing an MP's into Operations Manger through c sharp application. I need to consider all the exceptions ImportManagementPack() produces so that i can handle the exceptions carefully.