You create a System Center 2012 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.
Visual Basic Script | Copy Code |
---|---|
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 |
C# | Copy Code |
---|---|
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; } } |
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
Connection |
|
A valid connection to the SMS Provider. |
name |
|
The task sequence step name. |
description |
|
The task sequence step description. |
packageID |
|
The package identifier containing the software to be installed. Obtained from SMS_Package.PackageID. |
programName |
|
The name of the program to be installed. Obtained from SMS_Program.ProgramName. |
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 Connect to an SMS Provider in Configuration Manager by Using Managed CodeHow to Connect to an SMS Provider in Configuration Manager by Using WMI
How to Create an Operating System Deployment Task Sequence Package
Concepts
Configuration Manager Operating System DeploymentConfiguration Manager Objects
Configuration Manager Programming Fundamentals
Operating System Deployment Task Sequencing