In System Center 2012 Configuration Manager, you can reorder the steps (an action or a group) in a task sequence or group by rearranging the step sequence in the Steps property SMS_TaskSequences _Steps array.
To reorder a task sequence
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Obtain a valid task sequence (SMS_TaskSequence) or task sequence group (SMS_TaskSequence_Group). For more information, see How to Read a Task Sequence from a Task Sequence Package.
-
Within the Steps array property, move the SMS_TaskSequence_Step to its new location.
-
Update the task sequence or group.
Example
The following example shows how to move a step up or down within a task sequence or group.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Visual Basic Script | Copy Code |
---|---|
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 |
C# | Copy Code |
---|---|
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; } } |
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
taskSequence |
|
A valid task sequence (SMS_TaskSequence) or task sequence group (SMS_TaskSequence_Group) |
taskSequenceStepName stepName |
|
The name of the task sequence step (SMS_TaskSequence_Step) to move. |
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 Securing Configuration Manager Applications.
See Also
Tasks
How to Add an Operating System Deployment Task Sequence ActionHow 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
Concepts
Configuration Manager Operating System DeploymentConfiguration Manager Objects
Configuration Manager Programming Fundamentals
Operating System Deployment Task Sequencing