如何对操作系统部署任务序列进行重新排序

在Configuration Manager中,可以通过重新排列 Steps 属性SMS_TaskSequence_Step数组中的步骤序列,对任务序列或组中的操作或组) (步骤重新排序。

对任务序列进行重新排序

  1. 设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识

  2. 获取有效的任务序列 (SMS_TaskSequence) 或任务序列组 (SMS_TaskSequence_Group) 。 有关详细信息,请参阅 如何从任务序列包读取任务序列

  3. Steps 数组属性中,将 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 中的短信提供程序
任务序列概述