How to Use Task Sequence Variables in a Running Configuration Manager Task Sequence
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
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:
<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:
OSDPartitions0Bootable="true" OSDPartitions0FileSystem="NTFS" OSDPartition0QuickFormat="false" OSDPartitions0Size="100" OSDPartitions0SizeUnits="Percent" OSDPartitions0Type="Primary"
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:
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
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:
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 Microsoft.SMS.TSEnvironment.
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.
For more information about securing Configuration Manager applications, see About 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
Operating System Deployment Task Sequencing
How to Set an Operating System Deployment Task Sequence Variable