2

I have a task sequence with multiple Variables that are stored on the objects themselves. Running a dump out of the variables when the TS executes looks fine and I can see all of the variables I have created. However, when I create a package with a program inside my TS I need to be able to call those same variables INSIDE the program.

Is this possible in any way to carry over TS variables into a program?

djsnakz
  • 468
  • 2
  • 6
  • 15

1 Answers1

2

There is a COM Object "Microsoft.SMS.TSEnvironment" that can do this. So it depends mainly on the language your Program uses.

In VBScript it would be easy, e.g.:

Set smstsenv = CreateObject("Microsoft.SMS.TSEnvironment") 
strTSAdvID = smstsenv("_SMSTSAdvertID")

To get the Advertisement ID or

smstsenv.GetVariables

to get all Variables. Powershell would be equally trivial. C# or C++ should also be able to handle COM Objects. If your Language of choice does somehow not support them you could always wrap your program in a script, that reads the variable and passes it on, either as command line parameter or maybe set a normal windows environment variable with the same name,

Syberdoor
  • 2,521
  • 1
  • 11
  • 14
  • Thanks Syberdoor, You are exactly right, that is how it works inside a task sequence. However, I do not have trouble getting out the variables from the Task sequence. I have a package that is referenced in a task sequence. Now, that package has a program that runs a VBS Script. Inside that VBS script if you attempt to reference TS variables they are returned as null value. it appears to be that task sequence variables cannot be carried over into programs of packages that are references in task sequences. Task sequence steps such as "Run command line" have no issues with something like this. – djsnakz Jun 23 '15 at 08:53
  • That is strange, I specifically copied that example from a Program we run via "Install Package" in our Task Sequence. We were even asked by Microsoft to put it there and not execute it via run command line. Are you using a "legacy" package or an application ? – Syberdoor Jun 23 '15 at 09:23
  • We're using "legacy" package yes. does this change when switching to Application? – djsnakz Jun 23 '15 at 12:18
  • My Idea was that if you use Applications you could posibly run into some 32Bit/64Bit issues with the Com Object. Packages are always 32Bit though afaik and we are using the same and it works for us so it must be something different. Are all Variables empty or only specific ones? – Syberdoor Jun 23 '15 at 13:01
  • Thanks for your help. ill mark this as answered as it could just be COM object related when calling 64/32 bit differences within the TS. – djsnakz Jun 23 '15 at 23:41