如何将汇报添加到部署包

在 Configuration Manager 中,通过获取 SMS_SoftwareUpdatesPackage 类的实例并使用 AddUpdateContent 方法,向软件更新部署包添加更新。

创建软件更新部署包

  1. 设置与 SMS 提供程序的连接。

  2. 使用 SMS_SoftwareUpdatesPackage 类获取现有包对象。

  3. 使用 AddUpdateContent 方法将更新内容添加到现有包。

示例

以下示例方法演示如何使用 SMS_SoftwareUpdatesPackage 类和 AddUpdateContent 方法向软件更新部署包添加更新。

注意

更新必须作为 C#) 中的字典对象的 addUpdateContentParameters 一部分在内容源路径 (可用。 如果包源中存在更新,则该包源不能用于多个部署包。

重要

未包含任何 VBScript 示例,因为 AddUpdateContent 方法在失败时不会从方法调用返回。 这是一个已知问题,正在调查中。

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段

C# 中方法调用的示例:

// PREWORK FOR AddUpdatesToSUMDeploymentPackage  

// Define the array of Content Ids to load into addUpdateContentParameters.  
int[] newArrayContentIds = new int[] { 82 };  

// Define the array of source paths (these must be UNC) to load into addUpdateContentParameters.  
string[] newArrayContentSourcePath = new string[] { "\\\\ServerOne\\source1" };  

// Load the update content parameters into an object to pass to the method.  
Dictionary<string, object> addUpdateContentParameters = new Dictionary<string, object>();  
addUpdateContentParameters.Add("ContentIds", newArrayContentIds);  
addUpdateContentParameters.Add("ContentSourcePath", newArrayContentSourcePath);  
addUpdateContentParameters.Add("bRefreshDPs", false);  

AddUpdatestoSUMDeploymentPackage(WMIConnection,  
                                 "ABC00001",  
                                 addUpdateContentParameters);  
public void AddUpdatestoSUMDeploymentPackage(WqlConnectionManager connection,  
                                            string existingSUMPackageID,  
                                            Dictionary<string, object> addUpdateContentParameters)  
{  
    try  
    {  
        // Get the specific SUM Deployment Package to change.  
        IResultObject existingSUMDeploymentPackage = connection.GetInstance(@"SMS_SoftwareUpdatesPackage.PackageID='" + existingSUMPackageID + "'");  

        // Add updates to the existing SUM Deployment Package using the AddUpdateContent method.  
        // Note: The method will throw an exception, if the method is not able to add the content.  
        existingSUMDeploymentPackage.ExecuteMethod("AddUpdateContent", addUpdateContentParameters);  

        // Output a success message that the content was added.  
        Console.WriteLine("Added content to the SUM deployment package. ");                  
    }  
    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to add content to the SUM deployment package.");                  
        Console.WriteLine("Error: " + ex.Message);        
        throw;  
    }  
}  

示例方法具有以下参数:

参数 类型 说明
connection -管理: WqlConnectionManager 与 SMS 提供程序的有效连接。
existingSUMPackageID -管理: String 现有软件更新部署包的包 ID。
addUpdateContentParameters - 托管: dictionary 对象 参数集 (ContentIDs、、 ContentSourcePathbRefreshDPs) ,该参数将传递到 方法中,并与 方法调用一起使用AddUpdateContent

编译代码

此 C# 示例需要:

命名空间

System

System.Collections.Generic

System.Text

Microsoft。ConfigurationManagement.ManagementProvider

Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

关于软件更新部署如何将包分配到分发点
SMS_SoftwareUpdatesPackage
类SMS_SoftwareUpdatesPackage中的 AddUpdateContent 方法