如何從部署套件刪除更新
您可以從軟體更新部署套件移除更新,Configuration Manager取得SMS_SoftwareUpdatesPackage類別的實例,並使用RemoveContent方法。
從軟體更新部署套件刪除更新
設定與 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;
}
}
範例方法具有下列參數:
參數 | Type | 描述 |
---|---|---|
connection |
-管理: WqlConnectionManager |
SMS 提供者的有效連線。 |
existingSUMPackageID |
-管理: String |
現有軟體更新管理套件的套件識別碼。 |
removecontentParameters |
-管理: dictionary object |
參數集合 (ContentIDs , bRefreshDPs ) 傳遞至 方法並搭配 RemoveContent 方法呼叫使用。 |
正在編譯程式碼
此 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_SoftwareUpdatesPackage
類別SMS_SoftwareUpdatesPackage中的 RemoveContent 方法