If you have been working with SCCM deployments long enough, eventually you may encounter a need to display a window during running Task Sequence. It may be just a simple message box advising user to save all their data, up to more complex solutions with multiple options for the users. Whichever it might be, you first design and test your solution outside of Task Sequence and it works fine, then you try to run this inside of Task Sequence and… nothing happens.
This article will briefly guide you through how to show a custom message (topic covered widely on the net already), as well as how to ensure it doesn’t fail your Task Sequence in certain circumstances.
First of all, put together your PowerShell script with your custom window. As mentioned before, this can be a simple message box or a more complex solution, for example setting Task Sequence variables based on user’s choices – the sky is the limit. If you are planning a more complex solution, try building your own window using PowerShell and WPF – there is a brilliant tutorial on the topic that I can’t recommend enough: https://foxdeploy.com/2015/04/10/part-i-creating-powershell-guis-in-minutes-using-visual-studio-a-new-hope/
Once you have your script at hand, grab your latest MDT source media and copy ServiceUI.exe from Toolkit\Tools\x86 subfolder (you can use x86 executable on both x86 and x64 platforms.) to folder with your script’s source files. Next, wrap it all up in a Package (do not create a Program).
Last thing you need to do, is to call your PowerShell script through ServiceUI using the following syntax:
ServiceUI.exe -process:TSProgressUI.exe %windir%\sysnative\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -nologo -File Defer-Installation.ps1
We are done, right? Not quite. This will work just fine, as long as there is a user logged on. This may not always be the case if you are deploying your Task Sequence as Required. When Task Sequence runs this step with no user is logged on, it will typically fail with the follow error:
Process completed with exit code 4294967295 (...) ======================= Process Not Found: [TSProgressUI.exe] ======================= Exiting with [-1] ======================= (...) !--------------------------------------------------------------------------------------------! Failed to run the action: Defer installation script *. Unknown error (Error: FFFFFFFF; Source: Unknown)
Now, you can easily avert this failure by applying a WMI query on the Task Sequence step. You will find that some suggest using the following query:
SELECT * FROM Win32_ComputerSystem WHERE Username IS NOT NULL
This query checks if a user is logged on, however it is only limited to the local console session. Any user logged on via RDP will not be registered in Win32_ComputerSystem class. This solution might be good enough for your scenario, but if you want to cater for RDP users, you should use slightly different query. The original error message told us what the underlying problem was – the TSProgressUI.exe was not running. This means the Task Sequence was running, but it hasn’t spawned the process responsible for showing the progress, as there was no users to create it for. Therefore, our query should check if TSProgressUI.exe exists.
SELECT * FROM Win32_Process WHERE Name = "tsprogressui.exe"
This will work for both users logged in locally, as well as those logged in via RDP.