Last week I worked on BIOS updates for our Dell desktops and our HP laptops in Windows PE. The result was lots of new tasks in the task sequence with WMI queries to determine the model. After a BIOS update the machine needs a reboot, but doesn’t when already updated. To keep things fast and clean, I needed to find a solution to save time. I solved this with custom Task Sequence variables using PowerShell. Read along to find out how.
Using a PowerShell one-liner
Tasks within the task sequence were already built using the ‘Run a command line’ action. To keep things clean and simple, I wanted to integrate custom variables within the same task. This is where PowerShell comes in with just a one-liner that you can add alongside your initial commands.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('BIOSUpdated') = 'True'}"Note: PowerShell in Windows PE is required. Learn how on the Microsoft Docs.
Breaking down the one-liner
Let’s break down the one-liner to understand what it does. First, we take a look at the PowerShell executable and its arguments.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command| Argument | Description |
| -NoProfile | Makes sure there is no PowerShell profile used when executing the script. |
| -ExecutionPolicy Bypass | Bypass the standard execution policy to require signed PowerShell scripts. |
| -Command | Use inline PowerShell code. |
Create task sequence variables using PowerShell
The inline PowerShell code used after -Command enables us to set a task sequence variable, which we can use to store information about a passed event. For example, in my context, I need to know if the task sequence updated the BIOS on a computer. By setting a task sequence variable to True (BIOS update installed) or False (BIOS update not installed), I can easily use this information for subsequent tasks.
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$tsenv.Value('BIOSUpdated') = 'True'As a result, we can now add a condition for ‘Restart in Windows PE’, ensuring it does not run when the task sequence variable (BIOSUpdated) with the specific value (True) exists. This immediately results in shorter deployment times due to fewer restarts.
There is no limit on the number of task sequence variables you can set.

Conclusion
You’ve learned how to create task sequence variables with only one line of PowerShell code. Task sequence variables give you the ability to trigger or not trigger steps further down in your task sequence.
We can save valuable deployment time by using a PowerShell one-liner that sets a task sequence variable. It might seem unnecessary to save a few seconds or minutes per installation, but when you multiply those seconds or minutes by a few hundred or even thousands of devices, we actually save a significant amount of time (and money).
Do you have any questions or comments? Please feel free to get in touch.
One response
Hi Bjorn,
I am looking for a solution/script that would prompt/a dialog box during the light touch OSD TS to take the static IP address and other parameters for the server build. Any suggestions?