You delete an operating system deployment task sequence action, in System Center 2012 Configuration Manager, by removing the action from the task sequence steps.
To delete a task sequence action
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Obtain a task sequence (SMS_TaskSequence Server WMI Class) object. For more information, see How to Create an Operating System Deployment Task Sequence.
-
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.
Visual Basic Script | Copy Code |
---|---|
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 |
C# | Copy Code |
---|---|
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 |
|
A valid connection to the SMS Provider. |
taskSequence |
|
The task sequence containing the action to be deleted. |
actionName |
|
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
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