Using Task Sequence variables in a running Task Sequence by script is actually really straight forward. Also for most of you this might be common knowledge, but I noticed this week that it doesn’t count for everyone, yet. So in this post I will show the two (only two!) steps it takes to get or set variables with your script.
The first step is to create an instance of Microsoft.SMS.TSEnvironment. As this is a COM automation object, you could use every language that can use those. I will use VBScript in this example. Creating the object can be done by the following line of code:
set env = CreateObject(“Microsoft.SMS.TSEnvironment”)
Now that we’ve got our object the second step is to get, or set Task Sequence variables. This can be done by either one of the following lines of code:
GET: machineName = env(“_SMSTSMachineName”)
SET: env(“YourCustomVariable”) = “Your Custom Value”
By setting the new variable you can use any variable(name) that you want. If the variable does not exist, it will be created. If the variable does exist, its value will be updated.
For more information: http://msdn.microsoft.com/en-us/library/cc145669.aspx