If you work a lot with task sequences and want to perform advanced things, you’ve probably been a bit frustrated of not being able to branch your task sequence execution to a particular step (somethings like the GOTO command in the early BASIC language). Until now, this capability does not exists, but there something somewhat alike that allow to loop thru the same step. Here is how it works:
Context
If you are that kind of guy that put one command per step to keep the TS self documented, you’ll hardly be able to take benefit of this tip. Most of the time, the only suitable place to use a loop is within a script (VBS or Powershell). I’ve personally used it to set and upgrade BIOS in a single step in my own TS, but I’m well aware that is not a path everyone would like to walk, anyway this the price you’ll have to pay if you want or need to loop during a task sequence execution.
How To
The loop is enabled by setting up the following two properties:
- SMSTSRebootRequested=True
- SMSTSRetryRequested=True
Once the properties are set, the task sequence engine will reboot, and relaunch to the same step. Nice and simple.
Looping under WinPE.
One thing I've not yet told you, is that those properties works extremely well after the OS is deployed… before that… they simply don’t work and throw an error saying “Task sequence cannot continue after reboot because TS Manager is not configured to auto-start or GINA is not installed” !!!
So, is there a way to overcome this limitation ? Of course there is, this is unfortunately not documented but can be found in the SmsTs.log.
The trick is to set the property SMSTSRebootRequested to WinPE instead of True.
Once done, there is real magic happening: the WinPE image will eventually be pre staged on the destination hard drive if the action was initiated form a PXE boot.
Implementation
To demonstrate the reboot capability, I've made a simple VB script, that reboot 4 times in the same step and then proceed to the next one.
The script looks like this:
<job id="BIOSCheck">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
Option Explicit
RunNewInstance
Class TestReboot
Function Main
oLogging.CreateEntry "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" , LogTypeInfo
If oEnvironment.Exists("RebootCount") then
oEnvironment.Item("RebootCount") = oEnvironment.Item("RebootCount") + 1
Else
oEnvironment.Item("RebootCount") = 1
End If
oLogging.CreateEntry "Preparing to reboot for the "& oEnvironment.Item("RebootCount") & " Time" , LogTypeInfo
oUtility.SafeSleep 15000
If oEnvironment.Item("RebootCount") <= 3 then
If oEnvironment.Item("OSVersion") = "WinPE" Then
oEnvironment.Item("SMSTSRebootRequested") = "WinPE"
Else
oEnvironment.Item("SMSTSRebootRequested") = "true"
End If
oEnvironment.Item("SMSTSRetryRequested") = "true"
oLogging.CreateEntry "Reboot intitated, quit" , LogTypeInfo
Else
oLogging.CreateEntry "Looping Out of reboot, continuing TS execution!" , LogTypeInfo
End If
oLogging.CreateEntry "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" , LogTypeInfo
Main = SUCCESS
End Function
End class
</script>
</job>
The script should be placed in the Scripts folder of your Deployment Toolkit package, which means that MDT integration with SCCM is needed for this example, but is absolutely not mandatory to leverage loops!
And here is how looks the associated task sequence:
The First step format the disk with one standard MBR/NTFS partition. This is, of course, also working with a GPT/FAT partition.
The next two steps should be self explanatory, those are the “Use toolkit package” and Gather that you are already used to.
The “Test Reboot” step will execute the script pasted above with the following command: Cscript "%ScriptRoot%\TestReboot.wsf"
The final test is a pause initiated with the following command: cmd.exe /c start "Paused TS: Close this to continue" /wait cmd
Now you try !
this short example will hopefully help you envision how you can design yours scripts and task sequence differently. As I already mentioned, it have great potential in the BIOS configuration area. I hope many of you will find other spaces where it also feat well.Enjoy until next time.