Share via


How to Add a Step to an Operating System Deployment Group

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

You add a step (an action or a group) to an operating system deployment task sequence group, in Microsoft System Center Configuration Manager 2007, by adding the step to the SMS_TaskSequenceGroup.Steps array property.

To add a step to a task sequence group

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Get the SMS_TaskSequenceGroup object that you want to add the step to. For more information, see How to Create an Operating System Deployment Task Sequence Group.

  3. Create the task sequence step. For an example of creating an action step, see How to Add an Operating System Deployment Task Sequence ActionHow to Add an Operating System Deployment Task Sequence Action.

  4. Add the step to the SMS_TaskSequenceGroup.Steps array property.

  5. Reorder the step within the array property as necessary. For more information, see How to Reorder an Operating System Deployment Task Sequence

Example

The following example method adds a command-line action to a task sequence group.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub AddStepToGroup(taskSequenceStep, group)   

    Dim steps 

    ' If needed, create a new steps array.
    If IsNull(group.Steps) Then
        steps = Array(taskSequenceStep)
        group.Steps=steps
    Else
        ' Resize the existing steps and add step.
        steps= Array(group.Steps)
        ReDim steps (UBound (group.Steps)+1) 
        group.Steps(UBound(steps))=taskSequenceStep 
    End if 
     
End Sub
public void AddStepToGroup(
    WqlConnectionManager connection, 
    IResultObject taskSequence, 
    string groupName)
{
    try
    {
        // Get the group.
        List<IResultObject> steps = taskSequence.GetArrayItems("Steps"); // Array of SMS_TaskSequence_Steps.

        foreach (IResultObject ro in steps)
        {
            if (ro["Name"].StringValue == groupName && ro["__CLASS"].StringValue == "SMS_TaskSequence_Group")
            {
                IResultObject action = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_RunCommandLineAction");
                action["CommandLine"].StringValue = @"C:\donowtingroup.bat";
                action["Name"].StringValue = "Action in group " + groupName;
                action["Description"].StringValue = "Action in a group";
                action["Enabled"].BooleanValue = true;
                action["ContinueOnError"].BooleanValue = false;

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

                array.Add(action);

                ro.SetArrayItems("Steps", array);
                taskSequence.SetArrayItems("Steps", steps);
                break;
            }
        }
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to create Task Sequence: " + e.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

  • VBscript: SWbemServices

A valid connection to the SMS Provider.

taskSequence

  • Managed: IResultObject

  • VBScript: SWbemObject

  • A valid task sequence (SMS_TaskSequence).that contains the group.

groupName

  • Managed: String

  • VBScript: String

The name of the group that the command-line action is added to. This is obtained from the SMS_TaskSequenceGroup.Name property.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also

Concepts

Configuration Manager Operating System Deployment
Configuration Manager Objects
Configuration Manager Programming Fundamentals
How to Connect to an SMS Provider in Configuration Manager by Using Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using WMI
How to Move a Step to a Different Operating System Deployment Task Sequence Group
How to Create an Operating System Deployment Task Sequence Group
How to Remove a Step from an Operating System Deployment Group
Operating System Deployment Task Sequencing