LTI/ZTI PowerShell: Using PowerShell in Task Sequences

Now that we’re in the golden age of PowerShell many administrators will want to take advantage of its features in their deployments. With Lite/Zero-Touch you can do this by using the Run PowerShell Script task sequence step. The great thing is that now any PowerShell script that works in the OS can be coded to run in a task sequence.

This post demonstrates the simplest example of how to run a PowerShell script from within a task sequence. I’ll explain Parameters, Variables, logs, ZTIUtility.psm1 etc in future articles but right now I’m just going to keep it simple.

First, create a simple script.

Write-Output “Hello World” | Out-File $Home\Desktop\Hello.txt

This script outputs the phrase “Hello World” to a text file on the desktop. The reason we’re  outputting to a file is that the console is hidden during a task sequence and a pop-up box will halt the process.

Next, save the script in my deployment share in the scripts folder and call it ZTI-HelloWorld.ps1

Now create a basic Post-OS task sequence and add a the Run PowerShell Script task sequence step.

Run PowerShell Script

Modify the Task Sequence Step and add this command


Task Sequence Step

The %SCRIPTROOT% variable points to the Scripts folder on the deployment share or the script folder in the MDT package on SCCM.

Run this script on a test machine(as shown here.). This will create a file called Hello.txt on your desktop, the contents will say “Hello World”. MDT takes care of the Execution Policy for you by running the script unrestricted. MDT will also collect any errors returned by the script and store them in the deployment logs.

Next I’ll post an article about parameters and using variables from the CustomSettings.ini.


About Andrew Barnes

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

4 Responses to LTI/ZTI PowerShell: Using PowerShell in Task Sequences

  1. Tom Thompson says:

    When running PowerShell scripts like this do you have to worry about the script-executionpolicy? Or does MDT set it for you?


  2. GaryK says:

    I am finding this doesn’t work in our environment. It seems if your domain has a powershell execution policy in place, either unrestricted or remotesigned, MDT is not able to change the execution policy because group policy over-rides it. Even if the policy is unrestricted, the script stops, prompting for an ‘R’ for Run anyway. Do you have no execution policies set in your domain? Have you seen this problem before or have a solution?


    • The default execution policy is restricted. If you feel you need to stop rogue scripts then use this policy. I’m working in a large banking organisation with over 300,000 clients and they don’t feel the need to enforce the default execution policy. I’d ask your security to rethink this and let them know it’s interfering with your deployments.

      In the meantime, move your domain join after your scripts if you can.



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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s