How to Create an Operating System Deployment Task Sequence
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
You create a System Center 2012 R2 Configuration Manager operating system deployment task sequence by creating an instance of the SMS_TaskSequence class.
A task sequence contains one or more steps that are run sequentially on the client computer. For more information, see Operating System Deployment Task Sequence Object Model.
The task sequence is then packaged in an SMS_TaskSequencePackage Server WMI Class and advertised to the client computer.
To create a task sequence
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.
Add actions and, as required, add groups to the action. For more information, see How to Add an Operating System Deployment Task Sequence Action.
Associate the task sequence with a task sequence package. For more information, see How to Create an Operating System Deployment Task Sequence Package.
Advertise the task sequence to the client computer. For more information, see How to Create an Advertisement.
Example
The following example method creates a task sequence that installs a software program. The example also creates a task sequence package by calling the example that is defined in How to Create an Operating System Deployment Task Sequence Package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub CreateInstallSoftwareTaskSequence(connection,name, description, packageID, programName)
' Create the task sequence.
set taskSequence = connection.Get("SMS_TaskSequence").SpawnInstance_
' Create the action.
set action = connection.Get("SMS_TaskSequence_InstallSoftwareAction").SpawnInstance_
action.ProgramName=programName
action.PackageID=packageID
action.Name=name
action.Enabled=true
action.ContinueOnError=false
' Create an array to hold the action.
actionSteps= array(action)
' Add the array to the task sequence.
taskSequence.Steps=actionSteps
wscript.echo taskSequence.Steps(0).Name
call CreateTaskSequencePackage (connection, taskSequence)
End Sub
public void CreateInstallSoftwareTaskSequence( WqlConnectionManager connection, string name, string packageId, string programName) { try { // Create the task sequence. IResultObject taskSequence = connection.CreateInstance("SMS_TaskSequence"); IResultObject ro = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_InstallSoftwareAction"); ro["ProgramName"].StringValue = programName; ro["packageId"].StringValue = packageId; ro["Name"].StringValue = name; 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); // Create the task sequence package. this.CreateTaskSequencePackage(connection, taskSequence); } catch (SmsException e) { Console.WriteLine("Failed to create Task Sequence: " + 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 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
Operating System Deployment Task Sequencing
How to Create an Operating System Deployment Task Sequence Package
The example method has the following parameters:
Parameter
Type
Description
Connection
Managed:WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
name
Managed: String
VBScript: String
The task sequence step name.
description
VBScript: String
The task sequence step description.
packageID
Managed: String
VBScript: String
The package identifier containing the software to be installed. Obtained from SMS_Package.PackageID.
programName
Managed: String
VBScript: String
The name of the program to be installed. Obtained from SMS_Program.ProgramName.