Edit

Share via


How to Remove a Step from an Operating System Deployment Group

In Configuration Manager, you delete a step (an action or a group) from an operating system deployment task sequence group by deleting the step from the group's list of task sequence steps.

To remove a step from a group

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

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

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

Example

The following example method removes an action from a task sequence group.

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

Sub RemoveActionFromGroup(taskSequenceGroup, actionName)

    Dim i

    If taskSequenceGroup.SystemProperties_("__CLASS")<>"SMS_TaskSequence_Group" Then
        wscript.echo "Not a group"
        return
    End If

        Dim newArray
        Dim actionStep

        newArray = Array(taskSequenceGroup.Steps)
        ReDim newArray(UBound(taskSequenceGroup.Steps))

        i=0
        for each  actionStep in taskSequenceGroup.Steps
            If actionStep.Name = actionName and _
              actionStep.SystemProperties_("__SUPERCLASS") = "SMS_TaskSequence_Action" Then
                 ReDim preserve newArray(UBound(newArray)-1) ' shrink the Array
            else
               wscript.echo actionStep.Name
               Set newArray(i)=actionStep ' copy it
               i=i+1
            End If

         Next

         taskSequenceGroup.Steps=newArray

 End Sub
public void RemoveActionFromGroup(
    IResultObject taskSequenceGroup,
    string actionName)
{
    try
    {
        if (taskSequenceGroup["__CLASS"].StringValue != "SMS_TaskSequence_Group")
        {
            throw new System.InvalidOperationException("Not a group");
        }

        List<IResultObject> groupSteps = taskSequenceGroup.GetArrayItems("Steps");
        IResultObject actionFound = null;
        foreach (IResultObject actionStep in groupSteps)
        {
            if (actionStep["Name"].StringValue == actionName && actionStep["__SUPERCLASS"].StringValue == "SMS_TaskSequence_Action")
            {
                actionFound = actionStep;
                break;
            }
        }

        groupSteps.Remove(actionFound);
        taskSequenceGroup.SetArrayItems("Steps", groupSteps);
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to remove action: " + e.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description
taskSequenceGroup - Managed: IResultObject
- VBScript: SWbemObject
The task sequence group 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 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 Move a Step to a Different Operating System Deployment Task Sequence Group How to Create an Operating System Deployment Task Sequence Group Task sequence overview