Windows 10 Upgrade – Custom Action Scripts

Updated and More Detailed Page here: Windows Upgrade Custom Action Scripts (

Custom Action Scripts were new in Windows 10 1803. My Buddy Adam wrote up a great overview, so I’m not going to replicate that hard work, please check it out at his Blog.
Also, this is going to cover the SetupRollback.cmd file CM uses to re-trigger the TS in case of a Rollback.

What I’m going to try to better explain is when the scripts come in to play, and when they run when comparing to the actual upgrade process.

NOTHING IN THIS POST IS ANYTHING YOU’D WANT TO IMPLEMENT!!! This was only for learning exactly what these scripts do, so I can then see if they are useful to me in our upgrade process.

From the Docs:

[Sarcasm] So that clears it all up, you know exactly when they run [/Sarcasm].. plus it never tells you when the failure.cmd runs.

Test Process:

  • Create a Script that:
    • Creates each of the CMD Files & PowerShell Files used in Test
    • CMD files Call PowerShell Scripts (Because batch files are the worst)
      • preinstall.cmd -> preinstall.ps1
      • precommit.cmd -> precommit.ps1
      • failure.cmd -> failure.ps1
    • PowerShell Scripts write a time stamp to Registry.
  • Script is run in the Task Sequence right before Upgrade Steps


Creates the run and runonce folder, under both directories, the output will be identical.
under the Run \ RunOnce folders is a subfolder with a unique GUID, can be anything.
The Batch Files Call the PowerShell Scripts, that’s it.

Please note, you can do everything you want inside the batch file, if you don’t want to use PowerShell, you don’t have to. I just find that powershell is so much more powerful and easy to write complex scripts, that I don’t want to waste time writing a batch file.

PowerShell file writes a time stamp of when it ran to the registry.

I then trigger the upgrade:

preinstall.cmd happens when you start the Windows 10 Upgrade (Windows 10 Setup.exe), but before it actually starts the upgrade process.

precommit.cmd runs after the setup engine reaches 100% but before it reboots into the SafeOS

If you have a failed upgrade (has to make it first the downlevel phase, only kicks in during phase 2 and on), failure.cmd run at the same time as setuprollback.cmd which is once the the machine reverts and is back in a full OS.

Another visual of when they run:

If you use these scripts, and you make a mistake, or it returns a non-zero exit code, you can expect bad things in the way of failed upgrades. Depending on which script fails, you’ll see exit codes like this:

  • 0XC19001E2
    • MOSETUP_E_PREINSTALL_SCRIPT_FAILED A preinstall script failed to execute or returned an error.
  • 0XC19001E3
    • MOSETUP_E_PRECOMMIT_SCRIPT_FAILED A pre-commit script failed to execute or returned an error.
  • 0XC19001E4
    • MOSETUP_E_FAILURE_SCRIPT_FAILED A failure script failed to execute or returned an error.
  • 0XC19001E5
    • MOSETUP_E_SCRIPT_TIMEOUT A script exceeded the timeout limit.

Now if you want to setup a process for auto remediation, perhaps the eventhandler log. [MS Docs]

Testing Script:


5 thoughts on “Windows 10 Upgrade – Custom Action Scripts”

  1. Hi Gary, with the CM client agent for 1910, we discovered that the precommit phase is now executed after the first reboot. MS did this to resolve some instabilities that would occur during this phase and before the first reboot. With our Feature Update deployments, we relied on the precommit to control some things related to a UI that we’d use before the reboot occurs but we have to adjust that now. The new experience now shows a “working on updates” screen at shut down for a brief time and then reboots to the normal setup screens. FYI for those in a similar situation!

  2. How would you add task sequence variables to custom action scripts?
    As an example I have a requirement to use OSDSetupAdditionalUpgradeOptions and add a /pkey

    • Hey George, I stumbled on this post for something else, but saw your comment and decided to help in case you haven’t resolved your issue already. Right before your “Upgrade Operating System” step in your upgrade task sequence:
      1. create a “Set Task Sequence Variable” step, use the variable
      2. Set variable to: OSDSetupAdditionalUpgradeOptions
      3. Inside of Value, set your variables, such as:
      /pkey /ResizeRecoveryPartition Disable /DiagnosticPrompt disable /priority high

      • Sorry some of my text didn’t come through properly. Correction:
        1. create a “Set Task Sequence Variable” step
        2. Set variable to: OSDSetupAdditionalUpgradeOptions
        3. Inside of Value, set your parameters, such as:
        /pkey ABCD-1234-EFGH-JKLMN /ResizeRecoveryPartition Disable /DiagnosticPrompt disable /priority high

  3. Hi Christian,
    Thank you for this great writing, so appreciate your contribution.
    I have been tasked to upgrade all our windows 10 machines with Task Sequence to 21H1 version. Due to a couple of reboots that take place overnight, I have used a Pre-download method to push the Upgrade Package, which makes it available to the client machine in Software Center.
    Well, the company doesn’t want any user interaction, so there got to be another Task Sequence to initiate the installation from Software Center possibly with Run PowerShell script; That is where I need some help to launch the install automatically and would appreciate some help with such a script in my TS.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.