Come creare un elenco di aggiornamento

È possibile creare un elenco di aggiornamento contenente un set di aggiornamenti software in Configuration Manager creando un'istanza della classe SMS_AuthorizationList e popolando le proprietà.

Per creare un elenco di aggiornamento

  1. Configurare una connessione al provider SMS.

  2. Creare il nuovo oggetto elenco di aggiornamento usando la SMS_AuthorizationList classe.

  3. Popolare le proprietà del nuovo elenco di aggiornamento.

  4. Salvare il nuovo elenco di aggiornamento e le proprietà.

Esempio

Il metodo di esempio seguente mostra come creare un elenco di aggiornamento che contiene un set di aggiornamenti software creando un'istanza della classe e popolando le SMS_AuthorizationList proprietà.

Importante

La LocalizedInformation proprietà usata in questo esempio richiede una matrice di oggetti (matrice incorporata) delle informazioni di descrizione.

Nell'esempio LocaleID la proprietà è a codifica fissa in inglese (Stati Uniti). Se sono necessarie le impostazioni locali per i paesi non statunitensi installazioni, è possibile ottenerlo dalla proprietà SMS_Identification Server WMI ClassLocaleID .

Per informazioni sulla chiamata del codice di esempio, vedere Chiamata di frammenti di codice di Configuration Manager.

L'esempio seguente mostra la chiamata di subroutine 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)

L'esempio seguente mostra la chiamata al metodo 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;
    }
}

Il metodo di esempio include i parametri seguenti:

Parametro Tipo Descrizione
Connection - Gestito: WqlConnectionManager
- VBScript: SWbemServices
Una connessione valida al provider SMS.
newUpdates - Gestito: Integer array
- VBScript: Integer matrice
Una matrice degli aggiornamenti associati all'elenco degli aggiornamenti.
newDescriptionInfo - Gestito: Object array
- VBScript: Object matrice
Una matrice di oggetti (proprietà incorporate) del tipo LocalizedInformation.

Compilazione del codice

Questo esempio di C# richiede:

Spazi dei nomi

Sistema

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagementManagementProvider

Microsoft.ConfigurationManagementManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

Microsoft.ConfigurationManagement.ManagementProvider

Programmazione efficiente

Per altre informazioni sulla gestione degli errori, vedere Informazioni sugli errori di Configuration Manager.

Sicurezza di .NET Framework

Per altre informazioni sulla protezione delle applicazioni di Configuration Manager, vedere Amministrazione basata sui ruoli di Configuration Manager.

Vedere anche

Informazioni sulle distribuzioni degli aggiornamenti softwareSMS_AuthorizationList