During a task sequence run, it is useful to set task sequence variables to set conditions for tasks.
If using the Microsoft Deployment Tookit (MDT) task sequence variables are set for example when a virtual machine or laptop is detected.
$SMSTSEnv.Value("IsVM") will return True for virtual machines
$SMSTSEnv.Value("IsLaptop") will return True for laptops
These items can then be queried to control if laptop orientated tasks should activate.
To set a custom task sequence variable in a powershell script first create the object then set the variable value.
$SMSTSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment -ErrorAction SilentlyContinue
$SMSTSEnv.Value("TestVar")="TestVarValue"
Task sequence task options can then be conditioned on the task sequence variable value