共用方式為


如何設定及部署更新

您可以藉由建立 SMS_UpdatesAssignment Server WMI 類別的實例並填入屬性,在Configuration Manager中建立軟體更新部署。

設定及部署更新

  1. 設定與 SMS 提供者的連線。

  2. 使用 SMS_UpdatesAssignment 類別來 建立新的部署物件。

  3. 填入新的部署屬性。

  4. 儲存新的部署和屬性。

範例

下列範例方法示範如何使用 SMS_UpdatesAssignment 類別來建立軟體更新部署。 請注意,範例方法的參數會反映 的 SMS_UpdatesAssignment 特定屬性。

重要事項

下列方法需要指派組態專案的陣列 (CI_IDs) 。 這些CI_IDs的更新內容必須已經下載並新增至更新部署套件。

如需呼叫範例程式碼的相關資訊,請參閱呼叫Configuration Manager程式碼片段


Sub ConfigureAndDeploySUMUpdates(connection,                             _  
                                  newApplyToSubTargets,                  _  
                                  newArrayAssignedCIs,                   _  
                                  newAssignmentAction,                   _  
                                  newAssignmentDescription,              _  
                                  newAssignmentName,                     _  
                                  newDesiredConfigType,                  _  
                                  newDPLocality,                         _   
                                  newLocaleID,                           _  
                                  newLogComplianceToWinEvent,            _  
                                  newNotifyUser,                         _  
                                  newRaiseMomAlertsOnFailure,            _  
                                  newSendDetailedNonComplianceStatus,    _  
                                  newStartTime,                          _  
                                  newSuppressReboot,                     _  
                                  newTargetCollectionID,                 _  
                                  newUseGMTTimes)  

  ' Create the new deployment object.  
  Set newSUMUpdatesAssignment = connection.Get("SMS_UpdatesAssignment").SpawnInstance_  

  ' Populate the deployment properties.  
  newSUMUpdatesAssignment.ApplyToSubTargets = newApplyToSubTargets  
  newSUMUpdatesAssignment.AssignedCIs = newArrayAssignedCIs  
  newSUMUpdatesAssignment.AssignmentAction = newAssignmentAction  
  newSUMUpdatesAssignment.AssignmentDescription = newAssignmentDescription  
  newSUMUpdatesAssignment.AssignmentName = newAssignmentName  
  newSUMUpdatesAssignment.DesiredConfigType = newDesiredConfigType  
  newSUMUpdatesAssignment.DPLocality = newDPLocality  
  newSUMUpdatesAssignment.LocaleID = newLocaleID  
  newSUMUpdatesAssignment.LogComplianceToWinEvent = newLogComplianceToWinEvent  
  newSUMUpdatesAssignment.NotifyUser = newNotifyUser  
  newSUMUpdatesAssignment.RaiseMomAlertsOnFailure = newRaiseMomAlertsOnFailure  
  newSUMUpdatesAssignment.SendDetailedNonComplianceStatus = newSendDetailedNonComplianceStatus  
  newSUMUpdatesAssignment.StartTime = newStartTime  
  newSUMUpdatesAssignment.SuppressReboot = newSuppressReboot  
  newSUMUpdatesAssignment.TargetCollectionID = newTargetCollectionID  
  newSUMUpdatesAssignment.UseGMTTimes = newUseGMTTimes  

  ' Save the new deployment and properties.  
  newSUMUpdatesAssignment.Put_   

  ' Output the new deployment name.  
  Wscript.Echo "Created new deployment " & newSUMUpdatesAssignment.AssignmentName                    

End Sub  


public void ConfigureAndDeploySUMUpdates(WqlConnectionManager connection,  
                                        bool newApplyToSubTargets,  
                                        int[] newArrayAssignedCIs,  
                                        int newAssignmentAction,  
                                        string newAssignmentDescription,  
                                        string newAssignmentName,  
                                        int newDesiredConfigType,  
                                        int newDPLocality,  
                                        int newLocaleID,  
                                        bool newLogComplianceToWinEvent,  
                                        bool newNotifyUser,  
                                        bool newRaiseMomAlertsOnFailure,  
                                        bool newSendDetailedNonComplianceStatus,  
                                        string newStartTime,  
                                        int newSuppressReboot,  
                                        string newTargetCollectionID,  
                                        bool newUseGMTTimes)      
{  
    try  
    {  

        // Create the deployment object.  
        IResultObject newSUMUpdatesAssignment = connection.CreateInstance("SMS_UpdatesAssignment");  

        // Populate new deployment properties.  
        // Note: newTemplateName must be unique.  

        newSUMUpdatesAssignment["ApplyToSubTargets"].BooleanValue = newApplyToSubTargets;  
        newSUMUpdatesAssignment["AssignedCIs"].IntegerArrayValue = newArrayAssignedCIs;  
        newSUMUpdatesAssignment["AssignmentAction"].IntegerValue = newAssignmentAction;  
        newSUMUpdatesAssignment["AssignmentDescription"].StringValue = newAssignmentDescription;         
        newSUMUpdatesAssignment["AssignmentName"].StringValue = newAssignmentName;  
        newSUMUpdatesAssignment["DesiredConfigType"].IntegerValue = newDesiredConfigType;  
        newSUMUpdatesAssignment["DPLocality"].IntegerValue = newDPLocality;  
        newSUMUpdatesAssignment["LocaleID"].IntegerValue = newLocaleID;  
        newSUMUpdatesAssignment["LogComplianceToWinEvent"].BooleanValue = newLogComplianceToWinEvent;  
        newSUMUpdatesAssignment["NotifyUser"].BooleanValue = newNotifyUser;  
        newSUMUpdatesAssignment["RaiseMomAlertsOnFailure"].BooleanValue = newRaiseMomAlertsOnFailure;  
        newSUMUpdatesAssignment["SendDetailedNonComplianceStatus"].BooleanValue = newSendDetailedNonComplianceStatus;  
        newSUMUpdatesAssignment["StartTime"].DateTimeValue = newStartTime;  
        newSUMUpdatesAssignment["SuppressReboot"].IntegerValue = newSuppressReboot;  
        newSUMUpdatesAssignment["TargetCollectionID"].StringValue = newTargetCollectionID;  
        newSUMUpdatesAssignment["UseGMTTimes"].BooleanValue = newUseGMTTimes;  

        // Save new deployment and new deployment properties.  
        newSUMUpdatesAssignment.Put();  

        // Output the new deployment name.  
        Console.WriteLine("Created deployment: " + newAssignmentName);  
    }  

    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to create newSUMUpdatesAssignment. Error: " + ex.Message);  
        throw;  
    }  
}  

範例方法具有下列參數:

參數 Type 描述
Connection -管理: WqlConnectionManager
- VBScript: SWbemServices
SMS 提供者的有效連線。
newApplyToSubTargets -管理: Boolean
- VBScript: Boolean
判斷部署是否適用于子目標。

-真
-假
newArrayAssignedCIs - Managed: Integer 陣列
- VBScript: Integer 陣列
指派之組態專案的陣列 (CI_IDs) 。 這些CI_IDs的更新內容必須已經下載並新增至更新部署套件。
newAssignmentAction -管理: Integer
- VBScript: Integer
新的指派動作。
newAssignmentDescription -管理: String
- VBScript: String
新的指派描述。
newAssignmentName -管理: String
- VBScript: String
新的指派名稱。
newDesiredConfigType -管理: Integer
- VBScript: Integer
新的所需組態類型。
newDPLocality -管理: Integer
- VBScript: Integer
新的發佈點位置。
newLocaleID -管理: Integer
- VBScript: Integer
新的地區設定識別碼。
newLogComplianceToWinEvent -管理: Boolean
- VBScript: Boolean
判斷是否將合規性記錄到 Windows 事件記錄檔。

-真
-假
newNotifyUser -管理: Boolean
- VBScript: Boolean
識別使用者是否收到通知。

-真
-假
newRaiseMomAlertsOnFailure -管理: Boolean
- VBScript: Boolean
識別是否在失敗時引發 MOM 警示。

-真
-假
newSendDetailedNonComplianceStatus -管理: Boolean
- VBScript: Boolean
識別是否傳送詳細的不符合規範狀態。

-真
-假
newStartTime -管理: String
- VBScript: String
新的開始時間。
newSuppressReboot -管理: Integer
- VBScript: Integer
識別是否隱藏重新開機。
newTargetCollectionID -管理: String
- VBScript: String
新的目標集合識別碼。
newUseGMTTimes -管理: Boolean
- VBScript: Boolean
識別是否要使用國際標準時間 (UTC) 。

-真
-假

正在編譯程式碼

此 C# 範例需要:

命名空間

系統

System.Collections.Generic

System.Text

Microsoft。ConfigurationManagement.ManagementProvider

Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine

組件

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

健全的程式設計

如需錯誤處理的詳細資訊,請參閱關於Configuration Manager錯誤

.NET Framework 安全性

如需保護Configuration Manager應用程式的詳細資訊,請參閱Configuration Manager角色型系統管理

另請參閱

關於軟體更新部署

SMS_UpdatesAssignment