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:.
Now these drives only exist while a task sequence is running so Microsoft recommend that you add the line
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.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [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:
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.