Export (0) Print
Expand All

How to Enumerate the Steps in an Operating System Deployment Task Sequence

System Center

Updated: October 28, 2009

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 enumerate an operating system deployment task sequence, in Microsoft System Center Configuration Manager 2007, by using a recursive method to scan through the task sequence steps and groups.

To enumerate the steps in a task sequence

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

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

  3. Enumerate through the steps to display any action (SMS_TaskSequence_Actions names. Use recursion to access any groups (SMS_TaskSequence_Group) that are found and display their actions.

Example

The following example displays the actions and groups within a task sequence.

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

Sub RecurseTaskSequenceSteps(taskSequence, indent)

    Dim osdStep 
    Dim i
        
    ' Indent each new group.
    for each osdStep in taskSequence.Steps

        for i=0 to indent
            WScript.StdOut.Write " "
        next
        
        If osdStep.SystemProperties_("__CLASS")="SMS_TaskSequence_Group" Then
            wscript.StdOut.Write "Group: " 
        End If
        
        WScript.Echo osdStep.Name
      
        ' Recurse into each group found.
        If osdStep.SystemProperties_("__CLASS")="SMS_TaskSequence_Group" Then
            If IsNull(osdStep.Steps) Then
                Wscript.Echo "No steps"
            Else
                Call RecurseTaskSequenceSteps (osdStep, indent+3)
            End If    
        End If
     Next   
End Sub        
public void RecurseTaskSequenceSteps(
    IResultObject taskSequence,
    int indent)
{
    try
    {
        // The array of SMS_TaskSequence_Steps.
        List<IResultObject> steps = taskSequence.GetArrayItems("Steps");

        foreach (IResultObject ro in steps)
        {
            for (int i = 0; i < indent; i++)
            {
                Console.Write(" ");
            }

            if (ro["__CLASS"].StringValue == "SMS_TaskSequence_Group")
            {
                Console.Write("Group: ");
            }

            Console.WriteLine(ro["Name"].StringValue);

            // Child groups that are found. Use recursion to view them.
            if (ro["__CLASS"].StringValue == "SMS_TaskSequence_Group")
            {
                this.RecurseTaskSequenceSteps(ro, indent + 3);
            }
        }
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed To enumerate task sequence items: " + e.Message);
        throw;
    }
}

The example method has the following parameters:

 

Parameter Type Description

taskSequence

  • Managed: IResultObject

  • VBScript: SWbemObject

A valid task sequence (SMS_TaskSequence). The group is added to this task sequence.

indent

  • Managed: Integer

  • VBScript: Integer

Indent is used to space console output for child groups.

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

Show:
© 2014 Microsoft