Quantcast
Viewing latest article 4
Browse Latest Browse All 13

Windows 10 Upgrade - Custom Action Scripts

Updated and More Detailed Page here: Windows Upgrade Custom Action Scripts (recastsoftware.com)

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:

Image may be NSFW.
Clik here to view.

[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

Visually:

Image may be NSFW.
Clik here to view.
Creates the run and runonce folder, under both directories, the output will be identical.
Image may be NSFW.
Clik here to view.
under the Run \ RunOnce folders is a subfolder with a unique GUID, can be anything.
Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.

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

Image may be NSFW.
Clik here to view.

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.

Image may be NSFW.
Clik here to view.

Another visual of when they run:

Image may be NSFW.
Clik here to view.

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:

View the code on Gist.

GARYTOWN.COM


Viewing latest article 4
Browse Latest Browse All 13

Trending Articles