How to Use Task Sequence Variables in a Running Configuration Manager Task Sequence
In System Center Configuration Manager, you can create, get, and set task sequence variables in a running task sequence by using the task sequence environment COM automation object (
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 System Center Configuration Manager 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
When a task sequence variable is an array, it is passed in the following format:
<base array name><element #><Property>="value".
For example, the
OSDPartitions variable is an array of
SMS_TaskSequencePartitionSettings. The following represents a one element
OSDPartitions0Bootable="true" OSDPartitions0FileSystem="NTFS" OSDPartition0QuickFormat="false" OSDPartitions0Size="100" OSDPartitions0SizeUnits="Percent" OSDPartitions0Type="Primary"
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:
Windows Server 2008
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||1.0|
|Visual Studio 2005||2.0|
|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:
Reference to TSEnvironment 1.0 Type Library.
The TSEnvironmentLib namespace.
To use task variables in a running task sequence
In a running task sequence, create an instance of
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.
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
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.
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
Task sequence overview How to Set an Operating System Deployment Task Sequence Variable