OSDCloudGUI SetupComplete: Windows Updates

In a previous post I added some Task Sequence steps to Update our Windows image.

But, with the good work by @gwblok on the OSD module, we no longer need to do this. Back in March 2024 with version 24.3.6, some SetupComplete options were added and we can update windows using built-in features of the OSD module.

So lets see how this works by diving into the code and seeing it in action.

TL;DR

These options will create a SetupComplete.cmd & SetupComplete.ps1 file in the directory ‘C:\Windows\Setup\scripts’. The ‘SetupComplete.cmd’ will be called automatically by the windows installation and execute the ‘SetupComplete.ps1’ file. This script will have the commands necessary to install Windows Updates.

This will all take place during the first boot of windows. So your image will be update to date by the time you hit the OOBE.

OSDCloud / GUI Defaults

You can set these options by Default in the GUI using either the Start-OSDCloudGUI.json

Or by setting the variables in the $Global:MyOSDCloud variable which Gary shows here in GitHub issue 143.

Create the SetupComplete Files

So lets follow the code and see what gets setup to initiate the Windows Updates.

Once the Invoke-OSDCloud function gets called, and the OS Image has been applied, we get to the SetupComplete section of OSDCloud.

We start by calling the Set-SetupCompleteCreateStart function.

You can view the whole function on GitHub

  1. This array sets the Names of the files and the script path
  2. Then the SetupComplete.bat file is created
    • Within this section the command to run the ‘SetupComplete.ps1’ is added to the bat file on line 19.
  3. Finally the SetupComplete.ps1 file is created
    • This section also adds all the lines of Powershell needed to:
      • Import the OSD Module – Line 30
      • Import some additional functions – Line 31
      • Set the PowerPlan to High Performance – Lines 35-42
      • Call 2 additional functions to Modify the PowerPlan after everything has finished running

So now we have the files created, and added most of the necessary lines of PowerShell to the SetupComplete.ps1 script. Lets keep going.

Set-SetupCompleteStartWindowsUpdate

Back in Invoke-OSDCloud function, a check for $Global:OSDCloud.WindowsUpdate is made.

If true we run the function Set-SetupCompleteStartWindowsUpdate

You can view the whole function on GitHub

  1. In this section we check the SetupComplete.ps1 file exists
    • Then additional lines of PowerShell are added to the file
    • Specifically ‘Start-WindowsUpdate‘ on line 8

Lets take a look at this function

Start-WindowsUpdate

You can view the whole function on GitHub.

I’m not going to pretend to know exactly what is going on in the function. But it is utilizing the Windows Update Agent API to Search, Download and Install the Updates.

  1. Build the ComObjects for Searching, Downloading, and Installing the updates
  2. Search for updates using the Criteria
    • Accept the Eula
    • Title doesn’t match the term “Preview”
  3. If Updates are found
    • Download the Updates
    • Install the Updates

Set-SetupCompleteCreateFinish

Back again in the Invoke-OSDCloud function, after a bunch of other possible steps, we finally run the funtion Set-SetupCompleteCreateFinish

View the whole function on GitHub

This function wraps up the SetupComplete.ps1 file by:

  1. Checking again if the SetupComplete.ps1 file exists
    • Set the PowerPlan to ‘Balanced’
  2. Check if the option to Shutdown is set
    • If so, Stop-Transcript and shutdown the computer
  3. If not, Stop-Transcript and Restart the computer

When is the SetupComplete script running?

These setup complete steps will running during the ‘Just a moment’ screen.

Unfortunately you won’t see any pop-ups, windows, or notifications during this setup. You’ll just have to trust things are running smoothly.

What does it all look like?

Now lets look at the results of this after running it on a machine.

We can see the two Script files in the directory ‘C:\Windows\Setup\Scripts’

We can see the SetupComplete.cmd contains the command to call the ‘SetupComplete.ps1’ script

Next we can see the ‘SetupComplete.ps1’ script which contains the important section to run the ‘Start-WindowsUpdate’ function

To see output of the script, view the Log in the directory ‘C:\OSDCloud\Logs\SetupComplete.log’

And in this log file we can see that 6 Updates were successfully Installed.


There are other functions available that utilize the SetupComplete method. I plan to go over some of the HP ones as I would like to have a better understanding of what is going on as well.

But hopefully this helps others gain a better understanding of what is going behind the scenes not just with the Windows Update portion, but the other SetupComplete options.

Leave a Comment

Your email address will not be published. Required fields are marked *

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

Scroll to Top