Редагувати

Поділитися через


How to Enumerate the Available Operating System Deployment Task Sequences

You enumerate the available operating system deployment task sequences, in Configuration Manager, by querying the available task sequence packages. Configuration Manager does not maintain instances of the SMS_TaskSequence class for task sequences, but there is one instance of the SMS_TaskSequencePackage class for each task sequence.

Note

Several properties are lazy and you must get the object instance before you can access the properties.

You can also access individual task sequence packages by using the PackageID key property. For an example, see How to Read a Configuration Manager Object by Using Managed Code. After you have the task sequence package, you must create an SMS_TaskSequence object for the task sequence before you can change it. For more information, see How to Read a Task Sequence From a Task Sequence Package.

To enumerate the available task sequence packages

  1. Set up a connection to the SMS Provider. For more information, see SMS Provider fundamentals.

  2. Query the SMS Provider for the available instances of SMS_TaskSequencePackage.

  3. Display the required properties for each task sequence package returned by the query.

Example

The following example method queries the SMS Provider for the available instance of SMS_TaskSequencePackage. To retrieve the lazy properties, the example gets the entire object from the SMS Provider.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub EnumerateTaskSequencePackages(connection)  

    Set taskSequencePackages= connection.ExecQuery("Select * from SMS_TaskSequencePackage")  

    For Each package in taskSequencePackages  
        WScript.Echo package.Name  
        WScript.Echo package.Sequence  
    Next  
End Sub  
public void EnumerateTaskSequencePackages(  
    WqlConnectionManager connection)  
{  
    IResultObject taskSequencePackages = connection.QueryProcessor.ExecuteQuery("select * from SMS_TaskSequencePackage");  

    foreach (IResultObject ro in taskSequencePackages)  
    {  
        ro.Get();  

        // Get the lazy properties - Sequence property contains the Task sequence XML.  
        Console.WriteLine(ro["Name"].StringValue);  
        Console.WriteLine(ro["Sequence"].StringValue);  

        Console.WriteLine();  
    }  
}  

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

The 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.

.NET Framework Security

For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.

See Also

Objects overview 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
How to Read a Task Sequence From a Task Sequence Package
Task sequence overview