Last week I worked on BIOS updates for our Dell desktops and our HP laptops in Windows PE. I’ve created lots of new tasks 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.

Fix it with a one-liner

I already had my tasks built using the ‘Run a command line’ action. To keep things clean and simple, I wanted to integrate my 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.

A little side note: Make sure you use a Windows PE Environment with PowerShell support.

powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('BIOSUpdated') = 'True'}"

Let’s break it down

We need to call the PowerShell executable. Also, let PowerShell know what- and how it needs to run the script.

powershell.exe -NoProfile -ExecutionPolicy Bypass -Command
-NoProfileMakes sure the PowerShell profile isn’t loaded
-ExecutionPolicy BypassBypasses the execution policy of unsigned scripts so we don’t need to sign our own script
-CommandThe code we want to execute through PowerShell

Code to execute

We will create a variable called $Value and declare the actual value we want to assign to our tasks sequence variable. In my case I will use True, because I want to know if the task sequence executed a BIOS update.

Secondly, we will create a new object, which is the task sequence variable. We will tell that task sequence variable to name it BIOSUpdated and assign the variable $Value that stands for True.

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('BIOSUpdated') = 'True'

The benefit of this method for me, is that you can query your Restart into Windows PE step to not run when this task sequence variable with this specific value exists. It will save me precious deployment time and unnecessary restarts. You could use multiple variables with multiple values in your task sequence.

Wrapping things up

You’ve learned how to create task sequence variables with only one line of code with PowerShell. Task sequence variables will give you the ability to trigger (or not to trigger) steps further down in your task sequence. It will prevent tasks from running that in some scenarios are not mandatory.