How to Read a Task Sequence from a Task Sequence Package
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
You read a task sequence from a task sequence package, in System Center 2012 R2 Configuration Manager, by calling the SMS_TaskSequencePackage class GetSequence method. GetSequence returns an SMS_TaskSequence object that you can change and then put back in the package by using the SetSequence method. For an example of using SetSequence, see How to Create an Operating System Deployment Task Sequence Package.
To read a task sequence from a task sequence package
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Query the SMS Provider for the SMS_TaskSequencePackage that you want to load the sequence from.
Call the SMS_TaskSequencePackage class GetSequence method to get the SMS_TaskSequence object.
Make changes to the task sequence and put them back into the package by using SetSequence.
Example
The following example method returns the task sequence object (SMS_TaskSequence) from the supplied package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Function ReadTaskSequence(connection, taskSequencePackage)
' Get the parameters object.
Set packageClass = connection.Get("SMS_TaskSequencePackage")
Set objInParam = packageClass.Methods_("GetSequence"). _
inParameters.SpawnInstance_()
' Add the input parameters.
objInParam.Properties_.Item("TaskSequencePackage") = taskSequencePackage
' Get the sequence.
Set objOutParams = connection.ExecMethod("SMS_TaskSequencePackage", "GetSequence", objInParam)
Set ReadTaskSequence = objOutParams.TaskSequence
End Function
public IResultObject ReadTaskSequence( WqlConnectionManager connection, IResultObject taskSequencePackage) { IResultObject taskSequence = null; try { Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("TaskSequencePackage", taskSequencePackage); IResultObject outParams = connection.ExecuteMethod("SMS_TaskSequencePackage", "GetSequence", parameters); taskSequence = outParams.GetSingleItem("TaskSequence"); return taskSequence; } catch (Exception e) { Console.WriteLine("failed to hydrate: " + 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
How to Create an Operating System Deployment Task Sequence Package
Operating System Deployment Task Sequencing
How to Enumerate the Available Operating System Deployment Task Sequences
The example method has the following parameters:
Parameter
Type
Description
connection
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.