In System Center 2012 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 About the SMS Provider in Configuration Manager.

  2. Get the SMS_TaskSequenceGroup 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_TaskSequenceGroup.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.

Visual Basic Script  Copy Code
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
C#  Copy Code
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.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also