Dela via


Skapa en uppdateringslista

Du skapar en uppdateringslista som innehåller en uppsättning programuppdateringar i Configuration Manager genom att skapa en instans av klassen SMS_AuthorizationList och fylla i egenskaperna.

Så här skapar du en uppdateringslista

  1. Konfigurera en anslutning till SMS-providern.

  2. Skapa det nya uppdateringslistobjektet med hjälp av SMS_AuthorizationList klassen .

  3. Fyll i de nya egenskaperna för uppdateringslistan.

  4. Spara den nya uppdateringslistan och egenskaperna.

Exempel

Följande exempelmetod visar hur du skapar en uppdateringslista som innehåller en uppsättning programuppdateringar genom att skapa en instans av SMS_AuthorizationList klassen och fylla i egenskaperna.

Viktigt

Egenskapen LocalizedInformation som används i det här exemplet kräver en objektmatris (inbäddad matris) med beskrivningsinformationen.

I exemplet är egenskapen LocaleID hårdkodad till engelska (USA). Om du behöver nationella inställningar för icke-USA installationer kan du hämta den från egenskapen SMS_Identification Server WMI ClassLocaleID .

Information om hur du anropar exempelkoden finns i Anropa Configuration Manager-kodfragment.

I följande exempel visas subrutinanropet i 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)  

I följande exempel visas metodanropet i 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;  
    }  
}  

Exempelmetoden har följande parametrar:

Parameter Typ Beskrivning
Connection -Hanterade: WqlConnectionManager
– VBScript: SWbemServices
En giltig anslutning till SMS-providern.
newUpdates – Hanterad: Integer matris
– VBScript: Integer matris
En matris med de uppdateringar som är associerade med uppdateringslistan.
newDescriptionInfo – Hanterad: Object matris
– VBScript: Object matris
En objektmatris (inbäddade egenskaper) av typen LocalizedInformation.

Kompilera koden

Det här C#-exemplet kräver:

Namnområden

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Församling

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust programmering

Mer information om felhantering finns i Om Configuration Manager-fel.

.NET Framework Security

Mer information om hur du skyddar Configuration Manager-program finns i Rollbaserad administration i Configuration Manager.

Se även

Om programuppdateringsdistributionerSMS_AuthorizationList