次の方法で共有


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

Configuration Managerでは、タスク シーケンスまたはグループ内のステップ (アクションまたはグループ) を並べ替えるには、Steps プロパティSMS_TaskSequence_Step配列内のステップ シーケンス再配置します。

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

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

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

  3. array プロパティ内で StepsSMS_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 プロバイダーに接続する方法
タスク シーケンスの概要