So erstellen Sie eine Updateliste

Sie erstellen eine Updateliste, die eine Reihe von Softwareupdates enthält, in Configuration Manager, indem Sie eine instance der SMS_AuthorizationList Klasse erstellen und die Eigenschaften auffüllen.

So erstellen Sie eine Updateliste

  1. Richten Sie eine Verbindung mit dem SMS-Anbieter ein.

  2. Erstellen Sie das neue Updatelistenobjekt mithilfe der SMS_AuthorizationList Klasse.

  3. Füllen Sie die Eigenschaften der neuen Updateliste aus.

  4. Speichern Sie die neue Updateliste und die neuen Eigenschaften.

Beispiel

Die folgende Beispielmethode zeigt, wie Sie eine Updateliste erstellen, die eine Reihe von Softwareupdates enthält, indem Sie eine Instance der SMS_AuthorizationList Klasse erstellen und die Eigenschaften auffüllen.

Wichtig

Die LocalizedInformation in diesem Beispiel verwendete Eigenschaft erfordert ein Objektarray (eingebettetes Array) der Beschreibungsinformationen.

Im Beispiel ist die LocaleID Eigenschaft für Englisch (USA) hartcodiert. Wenn Sie das Gebietsschema für nicht-US-amerikanische können Sie sie aus der Eigenschaft SMS_Identification Server WMI-KlasseLocaleID abrufen.

Informationen zum Aufrufen des Beispielcodes finden Sie unter Aufrufen von Configuration Manager-Codeausschnitten.

Das folgende Beispiel zeigt den Unterroutinenaufruf in Visual Basic:


' Prework for CreateSUMUpdateList
' Create the array of CI_IDs.
dim newUpdates
newUpdates = Array(9)

' Create and populate an SMS_CI_LocalizedProperties object.
set SMSCILocalizedProperties = swbemservices.Get("SMS_CI_LocalizedProperties").SpawnInstance_

SMSCILocalizedProperties.Description = "Test Description"
SMSCILocalizedProperties.DisplayName = "Test Display Name"
SMSCILocalizedProperties.InformativeURL = "Test URL"
SMSCILocalizedProperties.LocaleID = "1033"

' Create an array to hold the SMS_CI_LocalizedProperties object.
dim newDescriptionInfo
newDescriptionInfo = Array(SMSCILocalizedProperties)

' Call the CreateSUMUpdateList method.
Call CreateSUMUpdateList(swbemServices,       _
                         newUpdates,          _
                         newDescriptionInfo)

Das folgende Beispiel zeigt den Methodenaufruf in C#:


// Prework for CreateSUMUpdateList
// Create array list (to hold the array of Localized Properties).
List<IResultObject> newDescriptionInfo = new List <IResultObject>();
IResultObject SMSCILocalizedProperties = WMIConnection.CreateEmbeddedObjectInstance("SMS_CI_LocalizedProperties");

// Populate the initial array values (this could be a loop to added more localized info).
SMSCILocalizedProperties["Description"].StringValue = "4 CI_IDs - 9,34,53,72 ";
SMSCILocalizedProperties["DisplayName"].StringValue = "Test Display Name";
SMSCILocalizedProperties["InformativeURL"].StringValue = "Test URL";
SMSCILocalizedProperties["LocaleID"].StringValue = "1033";

// Add the 'embedded properties' to newDescriptionInfo.
newDescriptionInfo.Add(SMSCILocalizedProperties);

// Create the array of CI_IDs.
int[] newCI_ID = new int[] { 9, 34, 53, 72 };

// Call the CreateSUMUpdateList method.
SUMSnippets.CreateSUMUpdateList(WMIConnection,
                                newCI_ID,
                                newDescriptionInfo);


Sub CreateSUMUpdateList(connection,         _
                        newUpdates,         _
                        newDescriptionInfo)

    ' Create the new UpdateList object.
    Set newUpdateList = connection.Get("SMS_AuthorizationList").SpawnInstance_

    ' Populate the UpdateList properties.
    ' Updates is an int32 array that maps to the CI_ID in SMS_SoftwareUpdate.
    newUpdateList.Updates = newUpdates
    ' Need to pass embedded properties (LocalizedInformation) here.
    newUpdateList.LocalizedInformation = newDescriptionInfo

    ' Save the new UpdateList and properties.
    newUpdateList.Put_

    ' Output the new UpdateList name.
    Wscript.Echo "Created Update List " & newUpdateList.LocalizedDisplayName

End Sub

public void CreateSUMUpdateList(WqlConnectionManager connection,
                                 int [] newUpdates,
                                 List<IResultObject> newDescriptionInfo)
{
    try
    {
        // Create the new SMS_AuthorizationList object.
        IResultObject newUpdateList = connection.CreateInstance("SMS_AuthorizationList");

        // Populate the new SMS_AuthorizationList object properties.
        // Updates is an int32 array that maps to the CI_ID in SMS_SoftwareUpdate.
        newUpdateList["Updates"].IntegerArrayValue = newUpdates;
        // Pass embedded properties (LocalizedInformation) here.
        newUpdateList.SetArrayItems("LocalizedInformation", newDescriptionInfo);

        // Save changes.
        newUpdateList.Put();

        Console.WriteLine();
        Console.WriteLine("Created Update List. " );

    }

    catch (SmsException ex)
    {
        Console.WriteLine("Failed to create update list. Error: " + ex.Message);
        throw;
    }
}

Die Beispielmethode hat die folgenden Parameter:

Parameter Typ Beschreibung
Connection - Verwaltet: WqlConnectionManager
- VBScript: SWbemDienste
Eine gültige Verbindung mit dem SMS-Anbieter.
newUpdates - Verwaltet: Integer Array
- VBScript: Integer Array
Ein Array der Updates, das der Updateliste zugeordnet ist.
newDescriptionInfo - Verwaltet: Object Array
- VBScript: Object Array
Ein Objektarray (eingebettete Eigenschaften) vom Typ LocalizedInformation.

Kompilieren des Codes

Dieses C#-Beispiel erfordert:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

Microsoft.ConfigurationManagement.ManagementProvider

Robuste Programmierung

Weitere Informationen zur Fehlerbehandlung finden Sie unter Informationen zu Configuration Manager-Fehlern.

.NET Framework-Sicherheit

Weitere Informationen zum Sichern von Configuration Manager-Anwendungen finden Sie unter rollenbasierte Verwaltung von Configuration Manager.

Siehe auch

Informationen zur Bereitstellung von SoftwareupdatesSMS_AuthorizationList