LTI/ZTI PowerShell: Accessing Task Sequence Variables

In order to create more useful scripts in your Lite/Zero-Touch deployments, you will need access to the deployment variables. In MDT 2012 you can now access these Task Sequence variables from 2 new PSDrives called TSEnv: and TSEnvList:.

TSEnv drive

Now these drives only exist while a task sequence is running so Microsoft recommend that you add the line

Import-Module .\ZTIUtility.psm1

to your scripts in order to create the drives for testing. You can also populate these drives with variables that you would expect to find when your script runs. It’s possible to access the variables in real time but to do this you will need to pause the Task Sequence while launching a PowerShell console, then import the module. This is how I do it.

First create a script that generates a message box and run it in a task sequence. This is my sample script. I’ve called it ZTI-MessageBox.ps1 and saved it in the scripts folder on my deployment share.

[System.Windows.Forms.MessageBox]::Show("Press ok to continue. . .")

Add it to a Run PowerShell Script task sequence.


Kick off the deployment from a client machine.


The script will now pause until you press ok. Now launch a PowerShell console and import the ZTIUtility by typing the following command:

Import-Module C:\MININT\Modules\ZTIUtility

Now, for this little trick to work you may have to configure the PowerShell script Execution Policy to RemoteSigned. This is because you’e working outside the task sequence in the machines environment. In my case it was a new test VM server.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Now you’ll have access to 2 new PSDrives. TSEnv: and TSEnvList:.

From here you can test your scripts with live data. Below are some sample variables and their values.


About Andrew Barnes

A Scripting and Deployment Specialist.
This entry was posted in Deployment, MDT 2010, MDT 2012, SCCM, Scripting and tagged , , , . Bookmark the permalink.

13 Responses to LTI/ZTI PowerShell: Accessing Task Sequence Variables

  1. Ben Hunter says:

    Hi Andrew,

    I thought you might be interested in a few interesting points about the way the “Run PowerShell Script” action works with MDT 2012 (and Update 1).
    1. The execution Policy is set to bypass automatically for the script.
    2. The MDT drives are automatically mounted
    3. The output of the script is added to bdd.log and scriptname.log

    Here is a very simple example script:

    Dir tsenv: out-host
    Write host “Is this a laptop – $TSenv:IsLaptop “
    $tsenv:IsLaptop = “Blah”

    This script will output all of the variables from TSENV, it will then tell us if we have a laptop, and finally we change the value of the IsLaptop variable.

    Hopefully all of these updates make using a PowerShell script with MDT easier.

    It is also worth noting that with the release of Update 1 this action also works with Windows 8.

    Ben Hunter


  2. Ben Hunter says:

    I also forgot to mention that I like the way you have paused the task sequence. This is a very useful technique for troubleshooting :).



  3. Jason Davis says:

    Have you been able to successfully do with with Server 2012 yet? I used a method similar to this to troubleshoot my PowerShell scripts on Server 2008 R2. On 2012 I am having trouble with Microsoft.BDD.TaskSequenceModule when I issue the Import-Module .\ZTIUtility (or any variation of that command to make sure I’m point to the correct path). I get the error ” Could not load file or assembly Microsoft.BDD.TaskSequenceModule.dll or one of its dependencies” “Operation is not Supported.”

    Just to clarify, I get that error when I pause the task sequence, then open a new Powershell prompt or ISE and use the import-module .\ZTIUtility. I’m just curious if I’m the only one having this problem and if anyone else has been successful in trying it on Server 2012.



    • Hi Jason,

      Sorry, I’ve not tried it on 2012 yet, I’m just working on another project before I can get my lab set up.

      The only issue I had was that the execution policy was preventing my from importing the module. After setting it right it was fine.


  4. B.S.Z. says:

    Hi Andrew. I’m having some issues with getting this pause tweak to work. I have SCCM deploying the script through an MDT task, the script gets to the point of running, and just completes, no message box being displayed. I was wondering if you had any ideas?

    SCCM 2012/MDT 2012 integrated, Win2k8 server.


  5. K says:

    Hi Barnes,

    I’ve extended my MDT database with some custom properties and I’m struggling in accessing them from the TSEnv in powershell. I’m adding my custom properties in the customsettings.ini file as below :


    I am missing something ?

    I’m trying to access the custom properties as below :


    Thanks for your help


  6. HI Andrew,
    thanks for your posts, ive been following your entire MDT blog and got it all working. i’ve created a post os task sequence to run powershell script to add printers using built in wins7 vbs scripts,

    prnmngr and prnport. code is working on the systems, but when run along with task sequence, powershells policy restriction is not allowing the script to execute.

    so added a cmd line with admin rights to change policy to unrestricted, but that approach didn’t work either. put a line on top of the script to import ztiutility, but came with an error saying cannot find the module in the deployment summary page. can you give me some pointers please.

    also, i have a custom wim image that i am deploying but the office licenses are getting stripped off, is there a way to automate the license key input..??? thanks in advance..


  7. Hi Andrew,
    I’ve just made an updated solution that doesn’t require launching task sequence anymore:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s