オペレーティング システム展開タスク シーケンスを並べ替える方法

Configuration Manager では、[ステップ] プロパティ SMS_TaskSequence_Step配列でステップ シーケンスを並べ替えることによって、タスク シーケンスまたはグループ内のステップ (アクションまたはグループ) を並べ替えることができます。

タスク シーケンスを並べ替えるには

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

  2. 有効なタスク シーケンス (SMS_TaskSequence) またはタスク シーケンス グループ (SMS_TaskSequence_Group) を取得します。 詳細については、「 タスク シーケンス パッケージからタスク シーケンスを読み取る方法」を参照してください。

  3. Steps array プロパティ内で、SMS_TaskSequence_Stepを新しい場所に移動します。

  4. タスク シーケンスまたはグループを更新します。

次の例は、タスク シーケンスまたはグループ内でステップを上下に移動する方法を示しています。

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

Sub MoveTaskSequenceStepDown(taskSequence, stepName)
   Dim index
   Dim osdStep
   Dim temp

    index=0

    ' If found, move the step down.
    for each osdStep in taskSequence.Steps
        If osdStep.Name=stepName Then
            If index < Ubound (TaskSequence.Steps) Then
                Set temp=osdStep
                taskSequence.Steps(index)=taskSequence.Steps(index+1)
                taskSequence.Steps(index+1)=temp
                Exit For
           End If
        End If

        index=index+1
    next
End Sub

Sub MoveTaskSequenceStepUp(taskSequence, stepName)
    Dim index
    Dim osdStep
    Dim temp

    index=0

    ' If found, move the step up.
    for Each osdStep In taskSequence.Steps
        If osdStep.Name=stepName Then
            If index >1 Then
                Set temp=osdStep
                taskSequence.Steps(index)=taskSequence.Steps(index-1)
                taskSequence.Steps(index-1)=temp
                Exit For
           End If
        End If

        index=index+1

    next
End Sub
public void MoveTaskSequenceStepDown(
    IResultObject taskSequence,
    string taskSequenceStepName)
{
    try
    {
        // Get the task sequence steps.
        List<IResultObject> steps = taskSequence.GetArrayItems("Steps"); // Array of SMS_TaskSequence_Steps.

        int index = 0;

        // Scan through the steps to find the step to move down.
        foreach (IResultObject ro in steps)
        {
            if (ro["Name"].StringValue == taskSequenceStepName)
            {
                // Move the step.
                if (index < steps.Count - 1) // Not at end, so we can flip.
                {
                    steps.Insert(index + 2, steps[index]);
                    steps.Remove(steps[index]);
                    taskSequence.SetArrayItems("Steps", steps);
                    break;
                }
            }

            index++;
        }
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed To enumerate task sequence items: " + e.Message);
        throw;
    }
}

public void MoveTaskSequenceStepUp(
    IResultObject taskSequence,
    string taskSequenceStepName)
{
    try
    {
        // Get the task sequence steps.
        List<IResultObject> steps = taskSequence.GetArrayItems("Steps"); // Array of SMS_TaskSequence_Steps.

        int index = 0;

        foreach (IResultObject ro in steps)
        {
            if (ro["Name"].StringValue == taskSequenceStepName)
            {
                if (index > 0) // Not the first step, so you can move it up.
                {
                    steps.Insert(index + 1, steps[index - 1]);
                    steps.Remove(steps[index - 1]);
                    taskSequence.SetArrayItems("Steps", steps);
                    break;
                }
            }
            index++;
        }
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed To enumerate task sequence items: " + e.Message);
        throw;
    }
}

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

パラメーター 説明
taskSequence - 管理対象: IResultObject
- VBScript: SWbemObject
有効なタスク シーケンスまたはタスク シーケンス グループ
taskSequenceStepName

stepName
- 管理対象: 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 プロバイダーに接続する方法タスク シーケンスの概要