How to Create an Operating System Deployment Task Sequence Group

An operating system deployment task sequence group, in Configuration Manager, can be added to a task sequence by creating an instance of the SMS_TaskSequence_Group class. The group is then added to the list of steps of the task sequence. The list of steps is an array of the SMS_TaskSequence_Step derived classes. The array is stored in the task sequence, SMS_TaskSequence, Steps property.

To create a task sequence group

  1. Set up a connection to the SMS Provider. For more information, see SMS Provider fundamentals.

  2. Obtain a valid task sequence (SMS_TaskSequence) object. For more information, see How to Create an Operating System Deployment Task Sequence.

  3. Create an instance of the SMS_TaskSequence_Group class.

  4. Populate the group with the appropriate properties.

  5. Update the task sequence Steps property with the new group.

Example

The following example method adds a new group to the supplied task sequence. Because the group is added to the end of the task sequence Steps array, you might want to reorder its position. For more information, see How to Reorder an Operating System Deployment Task Sequence.

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

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;  
    }  
}  

This 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). The group is added to this task sequence.
Name - Managed: String
- VBScript: String
A name for the new group.
Description - Managed: String
- VBScript: String
A description for the new group.
Parameter Description
connection A WqlConnectionManager object that is a valid connection to the SMS Provider.
taskSequence An IResultObject that is a valid task sequence (SMS_TaskSequence). The group is added to this task sequence.
name A string name for the new group.
description A string description for the new group.

Robust Programming

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

.NET Framework Security

For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.

See Also

Objects overview How to Add a Step to an Operating System Deployment Group
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 Create an Operating System Deployment Task Sequence
Task sequence overview