How to Remove a Step from an Operating System Deployment Group
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
In System Center 2012 R2 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
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
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.
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.
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; } }
Compiling the Code
This C# example requires:
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
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 Securing Configuration Manager Applications.
Configuration Manager Operating System Deployment
Configuration Manager Objects
Configuration Manager Programming Fundamentals
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
Operating System Deployment Task Sequencing
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.