Run a PowerShell script on System Startup in the OOBE Sysprep environment.

Jacob Raffoul 1 Reputation point
2022-04-24T03:50:04.27+00:00

Thanks for stopping by, I've searched the corners of the internet but haven't gotten anywhere.

To provision devices for my organization, we must manually run PowerShell commands using SHIFT + F10 in the Windows 11 OOBE as we have multiple methods, one of which being legacy. I'm sure there are better methods but I'm unfortunately working within these limitations. So far, to automate the imaging process, I've created an autounattend.xml which makes WinPE completely silent and some pages of the OOBE also.

Recently, I combined all the PowerShell commands we had been running prior into a script that, after running repeated checks for a network connection, prompts users with a GUI and effectively automates everything we had been doing manually before:
195825-777b8ee3-3546-48b7-a9dd-51c0c9c623a4.png

I need to make this run when the OOBE Sysprep starts, but I really need some help.

  • The script contains GUI, so it cannot run silently and the user needs to interact with it.
  • The script must start with the OOBE Windows Welcome Screen, (i.e. select region screen). This is a limitation of the modules used and I therefore can't include it as a synchronous command in FirstLogonCommands or include it in SetupComplete.cmd, as both are executed after the OOBE is completed.
  • I've tried configuring the answer file to boot into audit mode and have the script run there, but the script requires several reboots and I get an installation failed message after any reboot (despite later making the script enable the Administrator account and call "sysprep /audit /reboot"). Additionally, the Audit Administrator account takes ~15 minutes to log in so it defeats the whole purpose of time saving.
  • I've tried using Task Scheduler, testing triggers ;System Start Up; and 'User Log On', running as defaultuser0, BUILTIN\Administrators and SYSTEM. Task scheduler seems to either queue the task or not call it at all in the OOBE
  • I've tried placing the script, and then a shortcut of the script, in the common start up folder but that didn't work either.

To reiterate, I need a way to automatically run a script when the OOBE Sysprep starts. Furthermore, I need it to run every time the OOBE is launched as sometimes, we have to manually reboot if something glitches or goes wrong so the script will need to run again when the OOBE is resumed.

I know this is a tough one due to the limitations, but this will make the device rollout significantly easier.

Thanks,

Jake

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,166 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Limitless Technology 39,356 Reputation points
    2022-04-26T15:16:13.147+00:00

    Hello

    Thank you for your question and reaching out.

    I can understand you need to run PowerShell script during OOBE or WinPE.
    Please note that there is no Native method from Microsoft that you can run PowerShell script directly in Recovery or OOBE mode as it requires some dependencies.

    However you can use third party tools like OSDCloud to achieve this.


    --If the reply is helpful, please Upvote and Accept as answer--


  2. Akos 0 Reputation points
    2023-04-17T10:42:13.7333333+00:00

    Let’s check my solution here: https://akosbakos.ch/osdcloud-9-oobe-challenges/

    0 comments No comments

  3. Jacob Raffoul 1 Reputation point
    2023-04-17T11:03:45.5733333+00:00

    Hey everyone, I found the answer around August last year so I'm sorry for the delayed response. You can get scripts to run during the OOBE using Logon scripts in gpedit (Local Machine Group Policy), you can programmatically create them with PowerShell. They will open behind the OOBE interface, so it is best to use a program like NirCMD to hide the process Window.


  4. Steven Franks 0 Reputation points
    2023-12-21T10:09:38.71+00:00

    Hi Jacob,

    I'm attempting this at the minute. I don't need my implementation to do as much as yours does! Just need to automate getting oobe sorted as simply as possible.

    Do you have some pointers that might help me?

    Thank you in advance.

    0 comments No comments