So this is a topic that you can easily go through on the internet. But I have stubbleld on a specefic case that I havent seen mentionned any where else and which I will talk about in a few. But first let’s talk about the basis.

How to read task sequence variable with PowerShell

The Task sequence environement variables are easily accessible through the Microsoft.SMS.TSEnvironment ComObject .

To use this com object simply use the following line in your powershell script.

You can then easilly access any existing variable using the following syntax :

Using this line will retrieve the current logging path.

How to write new task sequence variables with Powershell ?

So know you know how to read the Built-in variables , you would most likely like create your own OSD variables ?

Well, powershell made it very very easy !

Yes, your read that correctly, I have a Youtube channel now. Check out the link below (I would love to hear your feedback about it)

https://www.youtube.com/@LearningInTheBasement

Now, you can access the variable “YoutubeChannel” through your task sequence like this:

$YoutubeUrl will contain the string : “https://www.youtube.com/@LearningInTheBasement

SCCM OSD Built-in variables list:

The most common ones (in my opinion) are the following ones :

Variable NameMeaning
_SMSTSInWinPE contains a boolean value saying if the task sequence is currently in WinPe mode or not
_SMSTSLogPathContains the path to the currently used log folder. (Since the paths are not the same depending on how far you are in your stagging process).
_SMSTSMachineNameThe machine name of the computer where the task sequence is currently executed on.

The complete variables used and accessible by SCCM during the task sequence can be found here:

  • SCCM 2012 and above click here
  • SCCM 2007 click here

Side note : All variables can be read and written except the ones starting with “_” (Underscore). They are read only variables.

So, that is for when everything goes well, and therefore we dont really really need help with (do we ??). Where it becomes a bit tricky is when you try to use your PowerShell script in a 64x Bits environment.

The 64x bits part :

So basically it is very easy to access the OSD variables using the very friendly Microsoft.SMS.TSEnvironment com object. But, there is a small drawback of using this comboject when using it on 64x bits machines : It simply doesn’t work.

Indeed, the comobject get actually always started in 32bits mode, even if it is running in a 64x bits environment. Which means that if you try to read the variables from PowerShell in a 64x bits envinroment, you will not see any variables.

When you need to access OSD variables in x64 bits mode from a PowerShell script, I recommend you try to avoid to read the varaibles directly from within the script (thus avoiding to use the Microsoft.SMS.TSEnvironment com object).

[stextbox id=”note”]Write your PowerShell script in a way so you can call the script with parameters, and give the OSD variables to your script as parameters.[/stextbox]

Still don’t see how to solve this ? see the examples below.

More SCCM osd variable manipulations:

Check my example out here: How to measure an SCCM task sequence execution time

Osd tattoo windows image –> Link

external and usefull links :

Technet article about SCCM variables : link

Article describing the Com object 64 bits issue : link