Importing Management Packs Programmatically (and How to Connect to a Management Server in an Untrusted Domain)
Published Feb 15 2019 04:33 AM 221 Views
First published on TECHNET on Dec 16, 2010

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("");
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)
cs.Password = ssPassword;

EnterpriseManagementGroup emg = new EnterpriseManagementGroup(cs);

//Import XML or .mp:
ManagementPack managementPack = new ManagementPack("C:\\Temp\\");

//Import MPB:
ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
ManagementPackBundle bundle = reader.Read("MyMP.mpb",emg);
Version history
Last update:
‎Mar 11 2019 08:37 AM
Updated by: