For some reason there is a requirement to do a computer shutdown (not restart) while running a task sequence, and once the computer starts again there is a need to continue running the task sequence where we left it.
How do you go about that? Let’st start…
We need two scripts, a task sequence with the ability to run one script and then to start a task sequence controlled restart.
For testing purposes a networkshare was used instead of leveraging a package, but in real-life and in production – all of the files can be placed in a package and executed from there.
This concept is tested within WinPE (using Winpeutil etc…), but you can most likely adapt it to a Windows installation.
Run Monitor
The ‘Run Monitor’ step will kick off a VB-Script that will start a powershell script – and then exit. Simple enough to start a script, and then allow the task sequence to continue with the next steps
VBScript
Runapp "powershell.exe","-noprofile -executionpolicy bypass -file " & GetScriptPatH() & "shutdown.ps1" Private Function RunApp(AppPath,Switches) Dim WShell Dim RunString Dim RetVal Dim Success On Error Resume Next Set WShell=CreateObject("WScript.Shell") RunString=Chr(34) &AppPath & Chr(34) & " " & Switches Retval=WShell.Run(RunString,0,False) RunApp=Retval Set WShell=Nothing End Function Private Function GetScriptPath GetScriptPath=Replace(WScript.ScriptFullName,WScript.ScriptName,"") End Function
The powershell-script (shutdown.ps1) looks as follows;
- Create a TS Environment (so we can read variables)
- Verify if the variable _SMSTSBootStagePath is set
- If the drive-part is longer than a single-letter – we know that the boot-image is prepared and that the reboot countdown has started.
Powershell
$end =$true write-output "start" DO { start-sleep 2 Get-date #Remove-Variable -name tsenv -Force -ErrorAction SilentlyContinue if (!$tsenv) { try { $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment } catch { write-output "No TS started yet" } } try { $bootpath = $tsenv.Value("_SMSTSBootStagePath") -split ":" $tsenv.Value("_SMSTSBootStagePath") if ($bootpath[0].length -gt 1) { write-output "SMSTSBootStagePath prepped for reboot" $end = $false } } catch { write-output "variable not set" } } While ($end -eq $true) start-sleep 5 wpeutil shutdown
Restart
The restart step is fairly generic and you can configure it as you need. A thing to note is that the time-out needs to be higher than the start-sleep within the Powershell-script. As the purpose is to continue within WinPE – the step is configured to start to the boot-image.
Thank you very much, exactly what I was looking for 🙂
Hello,
Can’t find the variable “_SMSTSBootStagePath” o SCCM. The powershell fails to execute, as it stays on a loop.
What I’m I missing?
Once a reboot action within a TS is started – what variables do exist?
Hey nickekallen
I am using a Task Sequence for Software update Installation on a Server which already is set up.
Your approach is working if a user is logged in, but when no user is logged in, there is no Notify Timeout and the “Restart Computer” Task fires immediately.
Do you have any idea how I could also wait with no user logged in?
thx
Hello,
As stated within the blog-post the above is only tested within WinPE (I suppose it has no user logged on?). I am not used to the restart occuring immediately if no user is logged on within a Windows installation – the timeout should still occur?
Thank you for answering – I know, but I thought maybe you know a workaround or smth like that 🙂
No, Unfortunately the timeout does not occur. The restart step starts immediately.
This should only apply if the restart was initiated via the software update step;
https://enterinit.com/controlling-reboot-timeout-and-reboot-message-when-using-install-software-updates-in-a-task-sequence/
A restart step should have these configurations visible within the task sequence editor – and to be honest I haven’t seen a case when they weren’t effective.
Fantastic, I finally got my Lenvo BIOS updates working in WinPE due to these scripts. I have combined the downloads made by the Driver Automation Tool, a Powershell script I wrote to install them in their downloaded form and your scripts to update Lenovo BIOS in the WinPE stage of an SCCM task sequence. I have modified my Poweshell script to also do HP and Dell using the downloads from the Driver Automation Tool. (I didn’t want to use the SCCM web service in their tool so I created an alternate method using strictly the downloads produced from their script)
John, it sounds like you are doing exactly what I am trying to do. Did these scripts above work for you with no modification? I copied and pasted and set up the TS the same and am getting a CScript Error: Execution of the Windows Script Host failed. (Not enough memory resources are available to complete this operation.)
then
Failed to run the action
Incorrect function. (Error: 00000001;Source: Windows)
Okay, so I eventually figured it out. Very unhelpful error messages. I used F8 to get to the command prompt and ran the script just fine with the same command line in the smsts.log file so the script was fine.
It ended up being that I put both scripts in a subfolder of an existing small package. It appeared to be found and using cscript subfolderrun.vbs appeared to work but it wasn’t. Once I got rid of the subfolder it worked. Strange but I’ll take it.
Thanks for sharing this nickekallen! I would not have figured this out on my own to get these Lenovo BIOS updates using flash.cmd to work.
Hi,
I’ve used your scripts to make the bios upgrade. it’s work well, but you may have to switch the first line of code in the vbs file.
you have to put that line after both declaration of the function. otherway, you will get error during the process
Can you provide your VBS code? I am trying to flash the BIOS in my OSD task sequence, its successful however after the flash the system boots into Windows without continuing the remaining task sequence; applying the BIOS config cctk file…..
My VBS script is exactly the same as the one givin by the author. the only modification i made was to take the first line “Runapp “powershell.exe”,”-noprofile -executionpolicy bypass -file ” & GetScriptPatH() & “shutdown.ps1″ ” and put it at the end of the file, after the declaration of the 2 function (Runapp and GetScriptPath).
for my part, i had to find the right place to put those steps in an existing sequence. i found that it was working when i had it after the installation of the “Setup Windows and ConfigMgr”, which is the installation of the sccm client if i got it right. at this point, it’s not in WinPE anymore. In our sequence, after this, we :
– install drivers
– restart the computer
– disable BitLocker (if configured in your environment)
– Apply bios update
– add the “Run monitor” script (for this test, the script is in the package of my bios, but we will create an independant package for this 2 scripts specificaly)
– and then add a restart computer steps with settings :
– The currently installed default operating system
– time-out of 60 seconds
when the sequence will restart at this stage, it will shutdown the computer, 1-2 seconds after it will reboot in the bios to Apply the update and continue it’s sequence
i hope it will give you some tracks to follow in your environment