Compartilhar via


How to Read a Task Sequence from a Task Sequence Package

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

You read a task sequence from a task sequence package, in Microsoft System Center Configuration Manager 2007, 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

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Query the SMS Provider for the SMS_TaskSequencePackage that you want to load the sequence from.

  3. Call the SMS_TaskSequencePackage class GetSequence method to get the SMS_TaskSequence object.

  4. 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;
    }
}

The example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

  • A valid connection to the SMS Provider.

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 About Securing Configuration Manager Applications.

See Also

Concepts

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