Exportieren von Konfigurationsbaselines und KonfigurationselementenHow to Export Configuration Baselines and Configuration Items
Um in Configuration Manager eine Konfigurations Basislinie oder ein Konfigurationselement mithilfe des Configuration Manager SDK zu exportieren, lesen Sie die relevante SMS_ConfigurationItem
Instanz, und schreiben Sie die- SDMPackageXML
Eigenschaft (Zeichenfolge) in eine Datei.In Configuration Manager, to export a configuration baseline or configuration item using the Configuration Manager SDK, read the relevant SMS_ConfigurationItem
instance and write the SDMPackageXML
property (string) to a file.
Wichtig
Die Codierung der XML-Datei muss auf UTF-16-codiertes Unicode festgelegt werden.The encoding of the XML file must be set to UTF-16 encoded Unicode.
So exportieren Sie Konfigurations Basis Linien und KonfigurationselementeTo export Configuration Baselines and Configuration Items
Richten Sie eine Verbindung mit dem SMS-Anbieter ein.Set up a connection to the SMS Provider.
Verwenden Sie die eindeutige ID des Konfigurations Elements (CI_ID), um die spezifische Instanz SMS_ConfigurationItem Klasse zu erhalten.Get the specific instance of SMS_ConfigurationItem class using the unique ID of the configuration item (CI_ID).
Kopieren Sie das Konfigurationselement XML (sdmpackagexml) in eine Variable.Copy the configuration item XML (SDMPackageXML) into a variable.
Schreiben Sie den XML-Inhalt des Konfigurations Elements in eine Datei.Write the configuration item XML content to a file.
BeispielExample
Das folgende Codebeispiel zeigt, wie Sie eine Instanz einer Konfigurations Basislinie oder eines Konfigurations Elements lesen und dann in eine Datei exportieren.The following code example shows how to read an instance of a configuration baseline or configuration item and then export it to a file.
Informationen zum Aufrufen des Beispielcodes finden Sie unter Aufrufen von Configuration Manager-Codeausschnitten.For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub DCMExportBaselineOrCI(swbemServices, _
pathToFile, _
configurationItemId)
' Set required variables.
fileContents = ""
configurationItemXML = null
' Get specified configuration item (configurationItemId variable).
Set getCIInfo = swbemServices.Get("SMS_ConfigurationItem.CI_ID=" & configurationItemId )
' Copy configuration item XML into variable.
configurationItemXML = getCIInfo.SDMPackageXML
Wscript.Echo configurationItemXML
' Open file for write (Unicode option enabled by second true).
Set FSO = CreateObject("Scripting.FileSystemObject")
Set textFile = FSO.CreateTextFile(pathToFile, true, true)
' Write XML content to file specified by pathToFile.
textFile.Write configurationItemXML
textFile.Close
Wscript.Echo " "
Wscript.Echo "Successfully wrote " & pathToFile
End Sub
public void DCMExportBaselineOrCI(WqlConnectionManager connection,
string pathToOutputFile,
string configurationItemId)
{
// Set required variables.
string configurationItemXML = null;
try
{
// Get the specified configuration item (configurationItemId variable).
IResultObject getCIInfo = connection.GetInstance(@"SMS_ConfigurationItem.CI_ID=" + configurationItemId);
// Copy configuration item XML into variable.
configurationItemXML = getCIInfo["SDMPackageXML"].StringValue;
}
catch (SmsException ex)
{
Console.WriteLine("Failed to retrieve configuration item xml. " + "\n" + ex.Message);
throw;
}
StreamWriter sw = null;
try
{
// Open file for output.
sw = new StreamWriter(pathToOutputFile, false, System.Text.Encoding.Unicode);
// Write XML to output file.
sw.Write(configurationItemXML);
}
catch (Exception ex)
{
Console.WriteLine("Failed to write configuration item XML to: " + pathToOutputFile + "\n" + ex.Message);
throw;
}
finally
{
if (sw != null)
{
sw.Close();
}
}
Console.WriteLine("Wrote configuration item XML to: " + pathToOutputFile);
}
Die Beispielmethode verfügt über die folgenden Parameter:The example method has the following parameters:
ParameterParameter | typeType | BESCHREIBUNGDescription |
---|---|---|
connection |
- Verwaltet: WqlConnectionManager - Managed: WqlConnectionManager - VBScript: SWbemServices- VBScript: SWbemServices |
Eine gültige Verbindung mit dem SMS-Anbieter.A valid connection to the SMS Provider. |
-pathdeoutputfile- pathToOutputFile -pathyfile- pathToFile |
- Verwaltet: String - Managed: String - VBScript: String - VBScript: String |
Der Pfad zur Ausgabedatei.Path to the output file. |
configurationItemId |
- Verwaltet: String - Managed: String - VBScript: String - VBScript: String |
Der Bezeichner eines zu exportierenden Konfigurations Elements.Identifier of a configuration item to export. |
Kompilieren des CodesCompiling the Code
NamespacesNamespaces
SystemSystem
System.Collections.GenericSystem.Collections.Generic
System.ComponentModelSystem.ComponentModel
Microsoft.ConfigurationManagement.ManagementProviderMicrosoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngineMicrosoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
AssemblyAssembly
adminui.wqlqueryengineadminui.wqlqueryengine
microsoft.configurationmanagement.managementprovidermicrosoft.configurationmanagement.managementprovider
Stabile ProgrammierungRobust Programming
Weitere Informationen zur Fehlerbehandlung finden Sie unter Informationen zu Configuration Manager-Fehlern.For more information about error handling, see About Configuration Manager Errors.
.NET Framework-Sicherheit.NET Framework Security
Weitere Informationen zum Sichern von Configuration Manager Anwendungen finden Sie unter Configuration Manager rollenbasierte Verwaltung.For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.
Weitere InformationenSee Also
Informationen zu konfigurationsbaselines und Konfigurationselementen About Configuration Baselines and Configuration Items
Übersicht über Objekte Vorgehens Weise beim Herstellen einer Verbindung mit einem Configuration Manager Anbieter mithilfe von verwaltetem Code Objects overview How to Connect to a Configuration Manager Provider using Managed Code
Vorgehensweise beim Herstellen einer Verbindung mit einem Configuration Manager-Anbieter mithilfe von WMI How to Connect to a Configuration Manager Provider Using WMI
WMI-Klasse für den SMS_BaselineAssignment Server SMS_BaselineAssignment Server WMI Class
WMI-Klasse für den SMS_ConfigurationItem ServerSMS_ConfigurationItem Server WMI Class