How to Delete an Operating System Deployment Task Sequence Action

You delete an operating system deployment task sequence action, in Configuration Manager, by removing the action from the task sequence steps.

To delete a task sequence action

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

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

  3. Remove the action from the SMS_TaskSequence.Steps array property.

Example

The following example method deletes an action from the task sequence. The action is identified as an action by checking the Windows Management Instrumentation (WMI) property __SUPERCLASS to ensure it derives from SMS_TaskSequenceAction.

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

Sub RemoveAction (connection, taskSequence, actionName)  

    Dim i  
    Dim newArray  
    Dim actionStep  

    If taskSequence.SystemProperties_("__CLASS")<>"SMS_TaskSequence" Then  
        wscript.echo "Not a task sequence"  
        Exit Sub  
    End If  

    if IsNull(taskSequence.Steps) Then  
        Wscript.Echo "No steps"  
        Exit Sub  
    End If  

    ' Create an array to hold copied steps.  
    newArray = Array(taskSequence.Steps)  
    ReDim newArray(UBound(taskSequence.Steps))  

    ' Copy the steps into the array and remove the matching action.  
    i=0  
    for each  actionStep in taskSequence.Steps  
        If actionStep.Name = actionName and _  
          actionStep.SystemProperties_("__SUPERCLASS") = "SMS_TaskSequence_Action" Then  
             ReDim preserve newArray(UBound(newArray)-1) ' shrink the Array  
        else  
           Set newArray(i)=actionStep ' copy it  
           i=i+1  
        End If     
     Next  

     ' Assign new array back to the task sequence.  
     taskSequence.Steps=newArray           

End Sub      
public void RemoveAction(  
    IResultObject taskSequence,   
    string actionName)  
{  
    try  
    {  
        // Get a list of steps.  
        List<IResultObject> actionSteps = taskSequence.GetArrayItems("Steps");  

        // Find the action to be deleted.  
        foreach (IResultObject actionStep in actionSteps)  
        {  
            if (actionStep["Name"].StringValue == actionName && actionStep["__SUPERCLASS"].StringValue == "SMS_TaskSequence_Action")  
            {  
                // Delete the action.  
                actionSteps.Remove(actionStep);  
                break;  
            }  
        }  

        // Update the task sequence.  
        taskSequence.SetArrayItems("Steps", actionSteps);  
    }  
    catch (Exception e)  
    {  
        Console.WriteLine("Failed to remove action: " + 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
The task sequence containing the action to be deleted.
actionName - Managed: String
- VBScript: String
The name of the action to be deleted. This can be obtained from the SMS_TaskSequenceAction.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.

.NET Framework Security

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

See Also

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