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.
Modify the Task Sequence Step and add this command
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.