展開パッケージから Updates を削除する方法

Configuration Manager でソフトウェア更新プログラム展開パッケージから更新プログラムを削除するには、SMS_SoftwareUpdatesPackage クラスのインスタンスを取得し、RemoveContent メソッドを使用します。

ソフトウェア更新プログラム展開パッケージから更新プログラムを削除するには

  1. SMS プロバイダーへの接続をセットアップします。

  2. SMS_SoftwareUpdatesPackage クラスを使用して既存のパッケージ オブジェクトを取得します。

  3. RemoveContent メソッドを使用して、既存のソフトウェア更新プログラム管理パッケージから更新プログラムのコンテンツを削除します。

次のサンプル メソッドは、 SMS_SoftwareUpdatesPackage クラスと RemoveContent メソッドを使用して、ソフトウェア更新プログラム展開パッケージから更新プログラムを削除する方法を示しています。

重要

RemoveContent メソッドは失敗時にメソッド呼び出しから返されないため、VBScript の例は含まれませんでした。 これは既知の問題であり、調査中です。

サンプル コードの呼び出しの詳細については、「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 メソッドに渡され、RemoveContent メソッド呼び出しで使用されるパラメーターのセット (ContentIDsbRefreshDPs)。

コードのコンパイル

この 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 ロールベースの管理」を参照してください。

関連項目

ソフトウェア更新プログラムの展開について How to assign a package to a distribution point SMS_SoftwareUpdatesPackageRemoveContent method in class SMS_SoftwareUpdatesPackage