Conditions
Overview
Conditions are the logic that determines which groups and steps run during a task sequence. A typical use case is deciding when to apply a driver pack. This is much less common in DeployR, because the "Inject drivers" and "Inject drivers from cloud" steps automatically match your driver pack content items based on make and model; ConfigMgr, however, relied heavily on conditions to apply the appropriate driver pack to a device. Other common examples are applying specific steps only during WinPE, performing additional steps based on the OS version being applied, or applying entirely different operating systems based on the hardware running the task sequence. Say you are running the task sequence on a laptop and want to make sure it is not on battery, or, if it is, skip several items so that it completes more quickly: that is all possible. Leveraging conditions allows for several "branches" off the main task sequence, covering additional scenarios without the need for additional task sequence deployments.
Adding a Condition
There are two types of conditions that can be added to a task sequence step or group:
Script (PowerShell)
Query Builder
To add a condition, first enter edit mode, then find the group or step on which you want to place the condition. Click the step or group so it is highlighted, then go to the Options tab. Once there, use the drop-down list to choose PowerShell or Query builder.

After selecting an option from the drop-down list, configure the condition.
Script
This method provides the most flexibility, as PowerShell can query a file path, registry property, or anything in WMI. For highly specific steps that are geared to very unique situations, scripts are the go-to method. I like to compare this to a Discovery / Detection script in Intune or ConfigMgr. The script only determines if remediation (the step) should run.
There is some logic behind how the script feature works, so the scripts need to be written with specific output:
If the return code is non-zero (either explicitly returned or generated because of a pipeline/script error), skip the step.
If the return code is zero and there is pipeline data returned, execute the step if there is a "true" boolean on the pipeline; skip the step if there is a "false" boolean on the pipeline. (If there is more than one, only the first is considered.)
If the return code is zero and there are no booleans, execute the step if there are any objects returned from the pipeline. Skip the step if there are none.
In summary, a script can return $true to run the step or $false to skip it. Alternatively, it can return an object to run the step or no objects to skip it. A non-zero return code always skips the step.
For example, to run the step on a Hyper-V virtual machine, either of these would cause the step to run:
The first example returns a 0 exit code (no errors) and a Boolean of "True".
The second example returns a 0 exit code (no errors) and an object.
Adding the Script option into the Conditions
From the drop-down box, select "Script" which is also the default, then insert your script into the editor. In this example, the script is set to make the Drivers group run on all devices that are NOT virtual machines.

Note: if you have other hypervisors in your environment, they might not use the model name "Virtual Machine", in which case this step will still run. To handle additional models, extend the script, like so:

Script Example for disabling peering on specific subnets based on gateway
As mentioned in the Peering & Content Basics page, there might be times you want to disable peering. Here is an example of using a condition to disable peering on specific networks based on the gateway.


Query Builder
The Query builder is a simple and effective way to quickly add logic into the task sequence.
The logic is like this: [Task Sequence Variable] equals (or not equals) [String]
Several queries can be added. A common combination is Model and OSCurrentBuild for applying a specific driver pack for a model with a specific OS.
In this example, the condition is true, and the step runs, only if the device is an HP and is running Windows 10 22H2 (19045).

Conditions can leverage either And (as used in the previous example) or Or logic. Use Or when the step should run if any one of several things is true. In this example, a new group is added with an "Or" logic, so now, besides being an HP device running 19045, this step will also run on any laptop, even if it is not an HP or running 19045.
When condition queries get more complex, you will need to put them in groups to get the outcome you want. This example shows a group that requires an HP device AND 19045, OR IsLaptop equals True. If either of those "statements" are True, then the step will run.

Last updated

