In Microsoft System Center Configuration Manager 2007, importing a configuration baseline or configuration item by using the Configuration Manager SDK requires a properly formatted XML file. Unlike the Configuration Manager console, the Configuration Manager SDK does not support directly importing a CAB file.

The encoding of the XML file must be set to UTF-16 encoded Unicode. The XML encoding can be identified in the XML header: <?xml version="1.0" encoding="utf-16" ?>

When configuration data is imported into Configuration Manager, the format can be one of the following:

Imported configuration data that contains only DCM Digest XML is converted into SML XML during the import process, and all configuration data is displayed and can be modified.

When the imported configuration data consists of SML XML only or contains some DCM Digest XML, some configuration item details might not be displayed in the Configuration Manager console. However, you can still add those configuration items to configuration baselines, and the configuration data is correctly interpreted by client computers when they evaluate their compliance.


The following code examples show how to create an instance of a configuration baseline or a configuration item and then populate it by importing a configuration baseline or a configuration item XML definition.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Visual Basic Script  Copy Code
Sub DCMImportBaselineOrCI(swbemServices,   _

' Set required variables.
readFile = 1  'constant 
fileContents		=	""
initialReadSucceeded  =	""
triStateTrue = -1  ' This sets the file read to Unicode.

' Check if source xml file exists.
set fileSytemObject = CreateObject("Scripting.FileSystemObject")
If fileSytemObject.FileExists(pathToFile) Then
	set textFile = fileSytemObject.OpenTextFile(pathToFile, readFile, False, triStateTrue)
	fileContents = textFile.ReadAll
	initialReadSucceeded = true

	set textFile = Nothing

	Wscript.Echo " "
	Wscript.Echo "Successfully read " & pathToFile

	initialReadSucceeded = false

	Wscript.Echo " "
	Wscript.Echo "File does not exist."
End If
set fileSytemObject = Nothing

If initialReadSucceeded Then

	On Error Resume Next 

		' Create an instance of configuration item.
		set newCI = swbemServices.Get("SMS_ConfigurationItem").SpawnInstance_()

		' Copy specified file contents (XML) into SMS_ConfigurationItem property.
		newCI.SDMPackageXML = fileContents

		' Save configuration item.

		If Err.Number<>0 Then
			Wscript.Echo "Couldn't create configuration item."
			Wscript.Echo "Possible duplicate configuration item or invalid XML."
		End If
	On Error Goto 0
	Wscript.Echo " "
	Wscript.Echo "Failed to create configuration item."   
End If  

End Sub
C#  Copy Code
public void DCMImportBaselineOrCI(WqlConnectionManager connection,
								string pathToFile)

	// Set required variables.
	string fileContents = null;
	bool initialReadSucceeded = false;

	// Load XML file using pathToFile variable.
		// Open the file specified by the pathToFile variable and read the contents into a string.
		using (StreamReader sr = new StreamReader(pathToFile, System.Text.Encoding.Unicode))
			fileContents = sr.ReadToEnd();

		Console.WriteLine("Successfully read " + pathToFile + ".");

		initialReadSucceeded = true;
	catch (Exception ex)
		Console.WriteLine("Unable to read " + pathToFile + "." + "\\n" + ex.Message);

	// Run only if the initial read was successful.
	if (initialReadSucceeded)
			// Create an instance of Configuration Item.
			IResultObject newCI = connection.CreateInstance("SMS_ConfigurationItem");

			// Copy specified file contents (XML) into SMS_ConfigurationItem property.
			newCI["SDMPackageXML"].StringValue = fileContents;

			// Save new SMS_ConfigurationItem object. 
		catch (SmsException ex)
			Console.WriteLine("Failed to create configuration item using " + pathToFile + ".");

Compiling the Code










Robust Programming

For more information about error handling, see About Configuration Manager Errors.


For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Send comments about this topic to Microsoft.