Windows 10: Unattended Execution of Powershell Script during Sysprep Process

Discus and support Unattended Execution of Powershell Script during Sysprep Process in Windows 10 Software and Apps to solve the problem; I'm trying to execute a PowerShell script unattendedly via the Sysprep process using the RunSynchronousCommand in the unattend.xml file, at the... Discussion in 'Windows 10 Software and Apps' started by Hanoch-S, Mar 20, 2025.

  1. Hanoch-S Win User

    Unattended Execution of Powershell Script during Sysprep Process


    I'm trying to execute a PowerShell script unattendedly via the Sysprep process using the RunSynchronousCommand in the unattend.xml file, at the specialize phase as Copilot strongly recommended.Despite following this syntax, the script isn't running as expected. Can anyone help me troubleshoot this issue?

    :)
     
    Hanoch-S, Mar 20, 2025
    #1
  2. PrasanRP Win User

    Unable to execute the Powershell scripts on Windows 11

    Hi,

    I am trying to execute the "Powershell" scripts on Windows 11 which was working great in Windows10.

    But, I am unable to execute it on Windows 11.

    So, I have tried executing the PS1 script is multiple ways,

    1. Right click -> Run Powershell

    => Powershell screen was blinked and gone.

    2. Launched the Powershell cmdlet with administrator and navigated to the script file location. Then executed the PS1 file.

    => refer the image for the error when we execute the script.

    3. Finally, I tried changing the execution policy using the Powershell cmdlet and I was able to execute my script (which was working in win10).

    Here, my question is the same script is working fine with Win10 without changing any policy. Then why it is not working with Win11 .

    1. Why it is required to change the policy ?

    2. Is it possible to execute the script in win11 without changing the policy ?

    3. What would be the root cause ? why is is not allowed ?

    4. What is the default execution policy for win 10 and win11 ? how it differs on execution?

    Please help me to understand the Powershell behavior and root cause of the problem.
     
    PrasanRP, Mar 20, 2025
    #2
  3. PrasanRP Win User
    Unable to execute the Powershell scripts on Windows 11

    In Windows 10, when I execute the PowerShell script, Execution policy is "Undefined" and I could see the "disable" error message .

    Even though, I am able to execute the PowerShell script content.
     
    PrasanRP, Mar 20, 2025
    #3
  4. Unattended Execution of Powershell Script during Sysprep Process

    How to make a PowerShell script run on System Startup in the OOBE Sysprep environment.

    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:


    Unattended Execution of Powershell Script during Sysprep Process 777b8ee3-3546-48b7-a9dd-51c0c9c623a4?upload=true.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 those both execute 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, running both on System Start Up and User Log On, as defaultuser0, BUILTIN\Administrators and SYSTEM. Task scheduler seems to either queue tasks or not call them 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
     
    Jacob Raffoul, Mar 20, 2025
    #4
Thema:

Unattended Execution of Powershell Script during Sysprep Process

Loading...
  1. Unattended Execution of Powershell Script during Sysprep Process - Similar Threads - Unattended Execution Powershell

  2. Unattended Execution of Powershell Script during Sysprep Process

    in Windows 10 Gaming
    Unattended Execution of Powershell Script during Sysprep Process: I'm trying to execute a PowerShell script unattendedly via the Sysprep process using the RunSynchronousCommand in the unattend.xml file, at the specialize phase as Copilot strongly recommended.Despite following this syntax, the script isn't running as expected. Can anyone...
  3. Unattended Execution of Powershell Script during Sysprep Process

    in Windows 10 Installation and Upgrade
    Unattended Execution of Powershell Script during Sysprep Process: I'm trying to execute a PowerShell script unattendedly via the Sysprep process using the RunSynchronousCommand in the unattend.xml file, at the specialize phase as Copilot strongly recommended.Despite following this syntax, the script isn't running as expected. Can anyone...
  4. Unable to execute the Powershell scripts on Windows 11

    in Windows 10 Software and Apps
    Unable to execute the Powershell scripts on Windows 11: Hi, I am trying to execute the "Powershell" scripts on Windows 11 which was working great in Windows10.But, I am unable to execute it on Windows 11. So, I have tried executing the PS1 script is multiple ways, 1. Right click -> Run Powershell=> Powershell screen was blinked...
  5. Unable to execute the Powershell scripts on Windows 11

    in Windows 10 Gaming
    Unable to execute the Powershell scripts on Windows 11: Hi, I am trying to execute the "Powershell" scripts on Windows 11 which was working great in Windows10.But, I am unable to execute it on Windows 11. So, I have tried executing the PS1 script is multiple ways, 1. Right click -> Run Powershell=> Powershell screen was blinked...
  6. How to turn on or off Windows PowerShell script execution

    in Windows 10 News
    How to turn on or off Windows PowerShell script execution: [ATTACH]If you want to turn on or off Windows PowerShell script execution in Windows […] This article How to turn on or off Windows PowerShell script execution first appeared on TheWindowsClub.com. read more...
  7. Powershell 2 scripts Execution

    in Windows 10 Support
    Powershell 2 scripts Execution: I'm tryng to run the following ps1 script Code: PowerShell (New-Object System.Net.WebClient).DownloadFile('https://server/file1.ps1','file1.ps1');Start-Process 'file1.ps1' PowerShell (New-Object...
  8. Unattended setup (Sysprep & unattend.xml) is not working for me

    in Windows 10 Installation and Upgrade
    Unattended setup (Sysprep & unattend.xml) is not working for me: I've been trying to create a customized Win10 Pro (Build 1903) install image for the last week or so. No matter how many tutorials I follow, answer files I create, or installs I perform, I just cannot get it to work properly. Every time I go to install Windows from my custom...
  9. Surface Pro 4 Unattended Sysprep Issue

    in Windows 10 Installation and Upgrade
    Surface Pro 4 Unattended Sysprep Issue: Hi Guys, Im attempting create an unattended sysprep windows 10 installation (1607) for the Surface Pro 4 using a USB and WinPE. I dont have the current script with me but the process is roughly the following; Install win 10 - audit mode Generate an unattend.xml using...
  10. Change PowerShell Script Execution Policy in Windows 10

    in Windows 10 Tutorials
    Change PowerShell Script Execution Policy in Windows 10: How to: Change PowerShell Script Execution Policy in Windows 10 How to Set PowerShell Script Execution Policy in Windows 10 The PowerShell script execution policies enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your...