如何从部署包中删除汇报
通过获取 SMS_SoftwareUpdatesPackage 类的实例并使用 RemoveContent 方法,在 Configuration Manager 中删除软件更新部署包中的更新。
从软件更新部署包中删除更新
设置与 SMS 提供程序的连接。
使用
SMS_SoftwareUpdatesPackage
类获取现有包对象。使用
RemoveContent
方法从现有软件更新管理包中删除更新内容。
示例
以下示例方法演示如何使用 SMS_SoftwareUpdatesPackage
类和 RemoveContent
方法从软件更新部署包中删除更新。
重要
未包含任何 VBScript 示例,因为 RemoveContent
方法在失败时不会从方法调用返回。 这是一个已知问题,正在调查中。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
C# 中方法调用的示例:
// Prework for RemoveUpdatesfromSUMDeploymentPackage.
// Define the array of Content IDs to load into the content parameters.
int[] newArrayContentIDs2 = new int[] { 82 };
// Load the update content parameters into an object to pass to the method.
Dictionary<string, object> removeContentParameters = new Dictionary<string, object>();
removeContentParameters.Add("ContentIDs", newArrayContentIDs2);
removeContentParameters.Add("bRefreshDPs", true);
// Call the RemoveUpdatesfromSUMDeploymentPackage method.
RemoveUpdatesfromSUMDeploymentPackage(WMIConnection,
"ABC00001",
removeContentParameters);
public void RemoveUpdatesfromSUMDeploymentPackage(WqlConnectionManager connection,
string existingSUMPackageID,
Dictionary<string, object> removeContentParameters)
{
try
{
// Get the specific SUM Deployment Package to change.
IResultObject existingSUMDeploymentPackage = connection.GetInstance(@"SMS_SoftwareUpdatesPackage.PackageID='" + existingSUMPackageID + "'");
// Remove updates from the existing SUM Deployment Package using the RemoveContent method.
// Note: The method will throw an exception, if the method is not able to add the content.
IResultObject result = existingSUMDeploymentPackage.ExecuteMethod("RemoveContent", removeContentParameters);
// Output a success message.
Console.WriteLine("Removed content from the deployment package. ");
}
catch (SmsException ex)
{
Console.WriteLine("Failed to remove content from the deployment package. Error: " + ex.Message);
throw;
}
}
示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
connection |
-管理: WqlConnectionManager |
与 SMS 提供程序的有效连接。 |
existingSUMPackageID |
-管理: String |
现有软件更新管理包的包 ID。 |
removecontentParameters |
-管理: dictionary object |
参数集 (ContentIDs , bRefreshDPs ) 传递到 方法中并与方法调用一起使用 RemoveContent 。 |
编译代码
此 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中的 RemoveContent 方法