Delen via


Een updatelijst maken

U maakt een updatelijst met een set software-updates in Configuration Manager door een exemplaar van de klasse SMS_AuthorizationList te maken en de eigenschappen te vullen.

Een updatelijst maken

  1. Een verbinding met de SMS-provider instellen.

  2. Maak het nieuwe updatelijstobject met behulp van de SMS_AuthorizationList klasse.

  3. Vul de eigenschappen van de nieuwe updatelijst in.

  4. Sla de nieuwe updatelijst en eigenschappen op.

Voorbeeld

In de volgende voorbeeldmethode ziet u hoe u een updatelijst maakt die een set software-updates bevat door een exemplaar van de SMS_AuthorizationList klasse te maken en de eigenschappen te vullen.

Belangrijk

Voor de LocalizedInformation eigenschap die in dit voorbeeld wordt gebruikt, is een objectmatrix (ingesloten matrix) van de beschrijvingsgegevens vereist.

In het voorbeeld is de LocaleID eigenschap vastgelegd in het Engels (VS). Als u de landinstelling nodig hebt voor niet-Amerikaanse installaties kunt u deze ophalen via de WMI-klasse-eigenschapLocaleID SMS_Identification-server.

Zie Configuration Manager-codefragmenten aanroepen voor meer informatie over het aanroepen van de voorbeeldcode.

In het volgende voorbeeld ziet u de subroutine-aanroep 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)  

In het volgende voorbeeld ziet u de methode-aanroep 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;  
    }  
}  

De voorbeeldmethode heeft de volgende parameters:

Parameter Type Beschrijving
Connection -Beheerd: WqlConnectionManager
- VBScript: SWbemServices
Een geldige verbinding met de SMS-provider.
newUpdates - Beheerd: Integer matrix
- VBScript: Integer matrix
Een matrix van de updates die is gekoppeld aan de updatelijst.
newDescriptionInfo - Beheerd: Object matrix
- VBScript: Object matrix
Een objectmatrix (ingesloten eigenschappen) van het type LocalizedInformation.

De code compileren

Voor dit C#-voorbeeld is het volgende vereist:

Naamruimten

Systeem

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Vergadering

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robuust programmeren

Zie Over Configuration Manager-fouten voor meer informatie over foutafhandeling.

.NET Framework-beveiliging

Zie Op rollen gebaseerd beheer van Configuration Manager voor meer informatie over het beveiligen van Configuration Manager-toepassingen.

Zie ook

Over software-update-implementatiesSMS_AuthorizationList