Cómo crear una lista de actualizaciones

Para crear una lista de actualizaciones que contenga un conjunto de actualizaciones de software, en Configuration Manager, se crea una instancia de la clase SMS_AuthorizationList y se rellenan las propiedades.

Para crear una lista de actualizaciones

  1. Configure una conexión al proveedor de SMS.

  2. Cree el nuevo objeto update list con la SMS_AuthorizationList clase.

  3. Rellene las nuevas propiedades de la lista de actualizaciones.

  4. Guarde la nueva lista de actualización y las propiedades.

Ejemplo

En el método de ejemplo siguiente se muestra cómo crear una lista de actualizaciones que contenga un conjunto de actualizaciones de software mediante la creación de una instancia de la SMS_AuthorizationList clase y el rellenado de las propiedades.

Importante

La LocalizedInformation propiedad que se utiliza en este ejemplo requiere una matriz de objetos (matriz incrustada) de la información de descripción.

En el ejemplo, la LocaleID propiedad está codificada de forma rígida en inglés (EE. UU.). Si necesita la configuración regional para aplicaciones que no sean de EE. UU. puede obtenerla de la propiedad SMS_Identification Server WMI ClassLocaleID .

Para obtener información sobre cómo llamar al código de ejemplo, consulte Llamar a fragmentos de código de Configuration Manager.

En el siguiente ejemplo se muestra la llamada a la subrutina en 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)

En el ejemplo siguiente se muestra la llamada al método en 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;
    }
}

El método de ejemplo tiene los siguientes parámetros:

Parámetro Tipo Descripción
Connection - Administrado: WqlConnectionManager
- VBScript: SWbemServices
Una conexión válida con el proveedor de SMS.
newUpdates - Administrado: Integer matriz
- VBScript: Integer matriz
Matriz de las actualizaciones asociadas a la lista de actualizaciones.
newDescriptionInfo - Administrado: Object matriz
- VBScript: Object matriz
Una matriz de objetos (propiedades incrustadas) del tipo LocalizedInformation.

Compilar el código

Este ejemplo de C# requiere:

Espacios de nombres

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Ensamblado

adminui.wqlqueryengine

Microsoft.ConfigurationManagement.ManagementProvider

Programación sólida

Para obtener más información acerca del control de errores, consulte Acerca de los errores de Configuration Manager.

Seguridad de .NET Framework

Para obtener más información acerca de cómo proteger las aplicaciones de Configuration Manager, consulte Administración basada en roles de Configuration Manager.

Vea también

Acerca de las implementaciones de actualización de softwareSMS_AuthorizationList