An operating system deployment task sequence action is added to a task sequence, in System Center 2012 Configuration Manager, by creating an instance of an SMS_TaskSequence_Action derived class and then adding it to the steps of the task sequence.
Note |
---|
System Center 2012 Configuration Manager has a number of built-in actions that you can use. For example the command-line action class is SMS_TaskSequence_RunCommandLineAction. These classes derive from the SMS_TaskSequence_Action class. |
SMS_TaskSequenceAction derives from the SMS_TaskSequence_Step class, which is the base class for both actions and groups. The task sequence stores its steps in an array of SMS_TaskSequence_Step, thus allowing actions and groups to be stored together.
To add a task sequence action
-
Set up a connection to the SMS Provider. For more information see, About the SMS Provider in Configuration Manager.
-
Create a task sequence (SMS_TaskSequence) object. For more information, see How to Create an Operating System Deployment Task Sequence.
-
Create an SMS_TaskSequenceAction derived class instance, for example, SMS_TaskSequence_RunCommandLine, for the action you want.
-
Populate the action as appropriate.
-
Add the action to the task sequences steps. This is stored the SMS_TaskSequence class Steps property.
Example
The following example method creates a command-line action and adds it to the supplied task sequence.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Visual Basic Script | Copy Code |
---|---|
Sub AddTaskSequenceActionCommandLine(connection, taskSequence, name, description) Dim steps Dim action Set action = connection.Get("SMS_TaskSequence_RunCommandLineAction").SpawnInstance_ action.CommandLine = "cmd /c Echo Hello" action.Name=name action.Description=description action.Enabled=True action.ContinueOnError=False If IsNull(taskSequence.Steps) Then steps = Array(action) taskSequence.Steps=steps Else steps= Array(taskSequence.Steps) ReDim steps (UBound (taskSequence.Steps)+1) taskSequence.Steps(UBound(steps))=action End if End Sub |
C# | Copy Code |
---|---|
public IResultObject AddTaskSequenceActionCommandLine( WqlConnectionManager connection, IResultObject taskSequence, string name, string description) { try { // Create the new step. IResultObject ro; ro = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_RunCommandLineAction"); ro["CommandLine"].StringValue = @"cmd /c Echo Hello"; ro["Name"].StringValue = name; ro["Description"].StringValue = description; ro["Enabled"].BooleanValue = true; ro["ContinueOnError"].BooleanValue = false; // Add the step to the task sequence. List<IResultObject> array = taskSequence.GetArrayItems("Steps"); array.Add(ro); taskSequence.SetArrayItems("Steps", array); return ro; } catch (SmsException e) { Console.WriteLine("Failed to add action: " + e.Message); throw; } } |
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection |
|
A valid connection to the SMS Provider. |
taskSequence |
|
A valid task sequence (SMS_TaskSequence). |
Name |
|
A name for the new action. |
Description |
|
A description for the action. |
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 a Condition to an Operating System Deployment Task Sequence StepHow 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 Create an Operating System Deployment Task Sequence Group
How to Delete an Operating System Deployment Task Sequence Action
Concepts
Configuration Manager Operating System DeploymentConfiguration Manager Objects
Configuration Manager Programming Fundamentals
Operating System Deployment Task Sequencing