如何创建作系统部署任务序列组

Configuration Manager,可以通过创建 SMS_TaskSequence_Group 类的实例,将作系统部署任务序列组添加到任务序列。 然后,该组将添加到任务序列的步骤列表中。 步骤列表是 SMS_TaskSequence_Step 派生类的数组。 数组存储在任务序列SMS_TaskSequenceSteps属性中。

创建任务序列组

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

  2. SMS_TaskSequence) 对象 ( 获取有效的任务序列。 有关详细信息,请参阅 如何创建作系统部署任务序列

  3. 创建 类的 SMS_TaskSequence_Group 实例。

  4. 使用适当的属性填充组。

  5. 使用新组更新任务序列 Steps 属性。

示例

以下示例方法将新组添加到提供的任务序列。 由于组已添加到任务序列 Steps 数组的末尾,因此可能需要对其位置重新排序。 有关详细信息,请参阅 如何对作系统部署任务序列进行重新排序

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段

Sub AddTaskSequenceGroup(connection, taskSequence, name, description)

    Dim group

    ' Create and populate the group.
    Set group = connection.Get("SMS_TaskSequence_Group").SpawnInstance_
    group.Name=name
    group.Description=description
    group.Enabled=True
    group.ContinueOnError=False

    ' Resize the task sequence steps array to hold the new group.
    ReDim steps (UBound (taskSequence.Steps)+1)

    ' Add the group.
    taskSequence.Steps(UBound(steps))=group

End Sub
public IResultObject AddTaskSequenceGroup(
    WqlConnectionManager connection,
    IResultObject taskSequence,
    string name,
    string description)
{
    try
    {
        // Create the new group.
        IResultObject ro = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_Group");

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

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

        // Add the new group to the end of the current steps.
        taskSequence.SetArrayItems("Steps", array);

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

此示例方法具有以下参数:

参数 类型 说明
connection -管理: WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
taskSequence -管理: IResultObject
- VBScript: SWbemObject
有效的任务序列 (SMS_TaskSequence) 。 组将添加到此任务序列。
Name -管理: String
- VBScript: String
新组的名称。
Description -管理: String
- VBScript: String
新组的说明。
参数 说明
connection 一个 WqlConnectionManager 对象,该对象是与 SMS 提供程序的有效连接。
taskSequence 一个 IResultObject ,它是 () SMS_TaskSequence 的有效任务序列。 组将添加到此任务序列。
name 新组的字符串名称。
description 新组的字符串说明。

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

对象概述如何向作系统部署组添加步骤如何使用托管代码连接到 Configuration Manager 中的 SMS 提供程序如何使用 WMI 连接到 Configuration Manager中的 SMS 提供程序如何创建作系统部署任务序列任务序列概述