Como criar uma lista de atualizações

Você cria uma lista de atualizações que contém um conjunto de atualizações de software, em Configuration Manager, criando uma instância da classe SMS_AuthorizationList e populando as propriedades.

Para criar uma lista de atualizações

  1. Configure uma conexão com o Provedor de SMS.

  2. Crie o novo objeto de lista de atualizações usando a SMS_AuthorizationList classe.

  3. Preencha as novas propriedades da lista de atualizações.

  4. Salve a nova lista de atualizações e as propriedades.

Exemplo

O método de exemplo a seguir mostra como criar uma lista de atualizações que contém um conjunto de atualizações de software criando uma instância da SMS_AuthorizationList classe e populando as propriedades.

Importante

A LocalizedInformation propriedade usada neste exemplo requer uma matriz de objeto (matriz inserida) das informações de descrição.

No exemplo, a LocaleID propriedade é codificada em código para inglês (EUA). Se você precisar da localidade para não-EUA. instalações, você pode obtê-lo na propriedade classe LocaleIDWMI do servidor SMS_Identification.

Para obter informações sobre como chamar o código de exemplo, consulte Chamando Configuration Manager Snippets de Código.

O exemplo a seguir mostra a chamada de sub-rotina no 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)  

O exemplo a seguir mostra a chamada do método em 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;  
    }  
}  

O método de exemplo tem os seguintes parâmetros:

Parâmetro Tipo Descrição
Connection -Gerenciado: WqlConnectionManager
- VBScript: SWbemServices
Uma conexão válida com o provedor de SMS.
newUpdates – Gerenciado: Integer matriz
- VBScript: Integer matriz
Uma matriz das atualizações associadas à Lista de Atualizações.
newDescriptionInfo – Gerenciado: Object matriz
- VBScript: Object matriz
Uma matriz de objeto (propriedades inseridas) do tipo LocalizedInformation.

Compilando o código

Este exemplo de C# requer:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Programação robusta

Para obter mais informações sobre o tratamento de erros, consulte Sobre erros de Configuration Manager.

Segurança do .NET Framework

Para obter mais informações sobre como proteger aplicativos Configuration Manager, consulte Configuration Manager administração baseada em função.

Confira também

Sobre implantações de atualizaçãode software SMS_AuthorizationList