オペレーティング システムの展開タスク シーケンスのアクションを追加する方法

オペレーティング システム展開タスク シーケンス アクションは、Configuration Manager で、SMS_TaskSequence_Action派生クラスのインスタンスを作成し、それをタスク シーケンスのステップに追加することによって、タスク シーケンスに追加されます。

注:

Configuration Manager には、使用できる多数の組み込みアクションがあります。 たとえば、コマンドライン アクション クラスは SMS_TaskSequence_RunCommandLineAction です。 これらのクラスは SMS_TaskSequence_Action クラスから派生します。

SMS_TaskSequenceAction は、アクションとグループの両方の基底クラスである SMS_TaskSequence_Step クラスから派生します。 タスク シーケンスは手順を SMS_TaskSequence_Step の配列に格納するため、アクションとグループを一緒に格納できます。

タスク シーケンス アクションを追加するには

  1. SMS プロバイダーへの接続をセットアップします。 詳細については、「 SMS プロバイダーの基礎」を参照してください。

  2. タスク シーケンス (SMS_TaskSequence) オブジェクトを作成します。 詳細については、「 オペレーティング システム展開タスク シーケンスを作成する方法」を参照してください。

  3. 目的のアクション用に、 SMS_TaskSequenceAction 派生クラス インスタンス ( SMS_TaskSequence_RunCommandLineAction など) を作成します。

  4. 必要に応じてアクションを設定します。

  5. タスク シーケンスの手順にアクションを追加します。 これは、 SMS_TaskSequence) クラスの Steps プロパティに格納されます。

次のサンプル メソッドは、コマンド ライン アクションを作成し、指定されたタスク シーケンスに追加します。

サンプル コードの呼び出しの詳細については、「Configuration Manager コード スニペットの呼び出し」を参照してください。

Sub AddTaskSequenceActionCommandLine(connection, taskSequence, name, description)

    Dim steps
    Dim action

    Set action = connection.Get("SMS_TaskSequence_RunCommandLineAction").SpawnInstance_

    action.CommandLine = "cmd /c Echo Hello"
    action.Name=name
    action.Description=description
    action.Enabled=True
    action.ContinueOnError=False

      If IsNull(taskSequence.Steps) Then
        steps = Array(action)
        taskSequence.Steps=steps
    Else
        steps= Array(taskSequence.Steps)
        ReDim steps (UBound (taskSequence.Steps)+1)
        taskSequence.Steps(UBound(steps))=action
    End if

End Sub

public IResultObject AddTaskSequenceActionCommandLine(
    WqlConnectionManager connection,
    IResultObject taskSequence,
    string name,
    string description)
{
    try
    {
        // Create the new step.
        IResultObject ro;

        ro = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_RunCommandLineAction");
        ro["CommandLine"].StringValue = @"cmd /c Echo Hello";

        ro["Name"].StringValue = name;
        ro["Description"].StringValue = description;
        ro["Enabled"].BooleanValue = true;
        ro["ContinueOnError"].BooleanValue = false;

        // Add the step to the task sequence.
        List<IResultObject> array = taskSequence.GetArrayItems("Steps");

        array.Add(ro);

        taskSequence.SetArrayItems("Steps", array);

        return ro;
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to add action: " + e.Message);
        throw;
    }
}

サンプル メソッドには、次のパラメータがあります:

パラメーター 説明
connection - 管理対象: WqlConnectionManager
- VBScript: SWbemServices
SMS プロバイダーへの有効な接続。
taskSequence - 管理対象: IResultObject
- VBScript: SWbemObject
有効なタスク シーケンス。
Name - 管理対象: String
- VBScript: String
新しいアクションの名前。
Description - 管理対象: String
- VBScript: String
アクションの説明。

コードのコンパイル

この C# の例では、次のものが必要です。

名前空間

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

Microsoft.ConfigurationManagement.ManagementProvider

adminui.wqlqueryengine

堅牢なプログラミング

エラー処理の詳細については、「Configuration Manager のエラーについて」を参照してください。

.NET Framework のセキュリティ

Configuration Manager アプリケーションのセキュリティ保護の詳細については、「Configuration Manager ロールベースの管理」を参照してください。

関連項目

オブジェクトの概要オペレーティング システムの展開タスク シーケンスの手順に条件を追加する方法マネージ コードを使用して Configuration Manager の SMS プロバイダーに接続する方法WMI を使用して Configuration Manager の SMS プロバイダーに接続する方法オペレーティング システム展開タスク シーケンス グループを作成する方法オペレーティング システムの展開タスク シーケンス アクションを削除する方法タスク シーケンスの概要