PowerShell is King – Using PowerShell in a Task Sequence – Part 1

Traditionally VBscript has been “the” script type to use in OS Deployment scenarios, but with WinPE 4.0 in the ADK and MDT 2012 (u1) it is now an option in some scenarios.


You would like to use a PowerShell script that uses properties from the ZTIGather process


Create the script and save it in the scripts folder in the deployment share (LTI) or in the MDT packages folder (ZTI) and then add it to the Task Sequence and if needed add any parameters you need to pass to the script. You don’t need to add any parameters from the LTI/ZTI environment, since they will be available within $TSenv:


The script:

Here is just a demo script that does not do anything at all, but it should give you an idea of how to create those scripts.


$ScriptFile = $MyInvocation.MyCommand.Name
$ScriptLocation  = Split-Path $MyInvocation.MyCommand.Path -Parent

#Setting Vars
$Make = $TSEnv:Make
$Model = $TSEnv:Model

#Performing Action
Write-Progress -Activity "Checking Hardware…" -Status "Running Inventory" -PercentComplete 12 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Running $ScriptFile" -PercentComplete 12 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Running $ScriptLocation" -PercentComplete 12 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Make is now $Make" -PercentComplete 32 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Model is now $MODEL" -PercentComplete 85 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Waiting when we are at 99% just because we can…" -PercentComplete 99 -Id 1
Start-Sleep -Seconds 3

Write-Progress -Activity "Checking Hardware…" -Status "Done" -PercentComplete 100 -Id 1
Start-Sleep -Seconds 3


Explaining the script:

The first block is just to set variables for the script it self, it s possible to use other methods, but I prefer to use the built-in method in PowerShell to find out where I am instead of using the translated way in LTI/ZTI

The next block is to show you how to convert a variable from the Task Sequence using the $TSEnv: drive. You don’t need to do this, it is possible to use $TSEnv:OSDComputername directly, but I think this is a bit easier.

Remaining blocks will display the information on the screen while running.

Download Script


Categories: Deployment, MDT, PowerShell, SCCM

Tagged as:

4 replies »

  1. Hi Mike. Was just wondering about leaving out “Import-Module .\ZTIUtility.psm1” as the (very basic) MDT PowerShell documentation says in the prerequisites for creating MDT PowerShell scripts, is it no longer needed?

    • It depends on how you run it, if you use the run pwershell script in the TS, you dont need it, but if you use powershell.exe as command or when you test the script outside the TS, well then you need it.

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.