Share via


Exit Code from Powershell GUI For SCCM OSD Task Sequence

Question

Tuesday, March 6, 2018 2:29 PM

Hi all,

I'm hoping someone can help with this problem.

I have a OS Upgrade Task Sequence that is pretty much vanilla.
The first step launches a Powershell GUI to the user, written by Maurice Daly (PowerShell GUI Restart Prompt)

I've modified it slightly so it presents the user with some text, an OK box and a Cancel button.
If the user clicks OK, the box closes and the TS continues.

I want the user to click Cancel and for the TS to exit.
I've tried setting a custom TS variable to 99, setting the next TS step to a command line 'cmd /c exit' with the option tab allowing this step to run if the TS variable does not equal 0.

It just ignores that and carries on with the TS.

I'd like to see if anyone has a solution showing how to capture the button click and pass that to the TS, or even just exit the TS within the Powershell script?

We're on SCCM v1710 and deploying Win10 v1709 as an upgrade.

Thanks, Marc

All replies (3)

Thursday, March 8, 2018 8:42 AM âś…Answered | 1 vote

Hi

There are two possible options I can think of. The first is to have the script return an exit code (e.g. Exit 99) and ensure the step does not 'continue on error'. This will make the TS fail but is not very elegant.

The second option is to still exit the script with and exit code (Exit 99) but set the 'Continue on error' option. Then below this step add a group which contains all the TS steps that would normally run when the user selects OK. Condition this group with a task sequence variable condition _SMSTSLastActionSucceeded equals "true".

When the user clicks Cancel and the script exits with the exit code the value of the _SMSTSLastActionSucceeded will be false and the group will not run, and the TS will end. However be aware that the TS will deem to have completed successfully which may not be what you want.

If you have MDT integrated with ConfigMgr you can create an MDT tasks sequence and look at how the "Gather Logs and StateStore on Failure" group works as this does the same thing but captures any error.

Regards Mark

Always learning.
If replies help, please either vote up or mark as answers.


Wednesday, March 7, 2018 4:16 PM

Hi,

Have you seen this? I hope it helps:

http://www.scconfigmgr.com/2013/10/02/prompt-for-computer-name-during-osd-with-powershell/

Please do a test in the experimental environment first.

Please remember to mark the replies as answers if they help. If you have feedback for TechNet Subscriber Support, contact [email protected].


Monday, March 12, 2018 5:11 PM

Thanks Mark,

As time is pressing, for now I opted to remove the 'Cancel' button and leave the user with a couple of minutes warning, but I will test out your second option idea.

Thank you very much!

Marc