In Microsoft System Center Configuration Manager 2007, you can create, get, and set task sequence variables in a running task sequence by using the task sequence environment COM automation object (Microsoft.SMS.TSEnvironment).

Typically, you use a command-line action that runs a script to access the task sequence variables. But you can also access them, within a running a task sequence, by using any programming environment that can use COM automation objects.

When you set a task variable on the Configuration Manager 2007 client, it becomes available to subsequent steps in the task sequence.

To create a custom task sequence variable, you set a Microsoft.SMS.TSEnvironment property by using the name of the new variable that you want to create. If the variable does not already exist, it is created. If the variable already exists, its value is updated. You can subsequently get the custom variable value from Microsoft.SMS.TSEnvironment.

When a task sequence variable is an array, it is passed in the following format:

  Copy Code
<base array name><element #><Property>="value".

For example, the OSDPartitions variable is an array of SMS_TaskSequencePartitionSettings. The following represents a one element OSDPartitions Array:

  Copy Code

To access FileSystem in this array, you would use OSDPartitions0FileSystem. If the array is larger, you would use OSDPartitions1FileSystem for the second element and so on through the array.

It is not recommended that you use managed code with the task sequencing environment because you cannot use it in the following environments:

Managed code does work when the full operating system is running with the correct version of .NET Framework installed.

The version of .NET Framework that is required depends on the version of Visual Studio that you use.

Visual Studio .NET Framework Version

Visual Studio 2003


Visual Studio 2005


Visual Studio 2008

2.0 to 3.5

You will need to use COM interop to access the TSEnvironment object. You will need the following:

To use task variables in a running task sequence

  1. In a running task sequence, create an instance of Microsoft.SMS.TSEnvironment.

  2. Get or set the required environment variable.


The following example method gets the _SMSTSLogPath variable. It also sets the value of a custom variable and an array custom variable value.

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

Visual Basic Script  Copy Code
Sub UseTaskSequenceVariables()
   dim osd: set env = CreateObject("Microsoft.SMS.TSEnvironment")
   dim logPath

   ' You can query the environment to get an existing variable.
   logPath = env("_SMSTSLogPath")

	wscript.echo logPath 

   ' You can also set a variable in the Operating System Deployment environment.
   env("MyCustomVariable") = "My Custom Value"

   ' Set the OSDPartitions(0) Bootable array member to 0.
	env("OSDPartitions0Bootable") = "true"
End Sub

Compiling the Code


Operating System Deployment task sequencing environment

Robust Programming

For more information about error handling, see About Configuration Manager Errors.


For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also

Send comments about this topic to Microsoft.