public/Update-OSDeployISO.ps1

#Requires -PSEdition Core

function Update-OSDeployISO {
    <#
    .SYNOPSIS
        Rebuilds the bootable ISO files for a selected OSDeployCore BootImage build.
 
    .DESCRIPTION
        Regenerates the ISO files (bootmedia.iso and optionally bootmedia_ca2023.iso) for
        a selected completed BootImage from %ProgramData%\OSDeployCore\boot-media. The
        existing bootmedia directory content is used as-is; no DISM mount or WIM modification
        is performed.
 
        The function:
        - Prompts for selection of a completed BootImage build
        - Verifies the Windows ADK is installed
        - Uses the installed ADK's oscdimg.exe to rebuild the ISO(s)
        - Places ISOs in the BootImage's root directory
 
    .EXAMPLE
        Update-OSDeployISO
        Prompts for a BootImage build selection and rebuilds its ISO files using the installed ADK.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        None.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: April 2026
 
        Prerequisites:
            - PowerShell 7.0 or higher (Core edition)
            - Windows 10 or higher
            - Run as Administrator
            - Windows ADK installed
            - At least one completed BootImage build in %ProgramData%\OSDeployCore\boot-media
 
    .LINK
        https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install
    .LINK
        https://github.com/OSDeploy/OSDeploy
    #>


    [CmdletBinding()]
    param ()
    #=================================================
    Write-OSDeployBanner
    $Error.Clear()
    Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Start"
    Initialize-OSDeployCoreBootImage
    #=================================================
    # Requires Run as Administrator
    $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    if (-not $IsAdmin) {
        Write-Warning "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] This function must be Run as Administrator"
        return
    }
    #=================================================
    # Select a BootImage build
    $SelectBootImage = Select-OSDeployCoreBootImage
    if ($null -eq $SelectBootImage) {
        Write-Warning "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] No OSDeployCore BootImage build was found or selected"
        return
    }
    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Selected BootImage: $($SelectBootImage.Name)"
    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] BootImage path: $($SelectBootImage.Path)"
    #=================================================
    # Verify Windows ADK is installed
    $AdkInfo = Get-WindowsAdkInstallInfo
    if (-not $AdkInfo.IsInstalled) {
        Write-Warning "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Windows ADK is not installed"
        Write-Warning "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Install the Windows ADK from https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install"
        return
    }
    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Windows ADK version $($AdkInfo.InstallVersion) at $($AdkInfo.InstallPath)"
    #=================================================
    # Build media paths
    $MediaPath = Join-Path $SelectBootImage.Path 'bootmedia'
    if (-not (Test-Path -Path $MediaPath)) {
        Write-Warning "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] bootmedia directory not found: $MediaPath"
        return
    }

    $MediaPathEX = Join-Path $SelectBootImage.Path 'bootmedia_ca2023'
    if (-not (Test-Path -Path $MediaPathEX)) {
        $MediaPathEX = $null
    }
    #=================================================
    # Set BuildMedia global for Step-BootImageIso
    $global:BuildMedia = [ordered]@{
        AdkRootPath   = $AdkInfo.InstallPath
        MediaIsoLabel = $SelectBootImage.Name
        MediaPath     = $MediaPath
        MediaPathEX   = $MediaPathEX
        MediaRootPath = $SelectBootImage.Path
    }

    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] MediaPath: $MediaPath"
    if ($MediaPathEX) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] MediaPathEX: $MediaPathEX"
    }
    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] MediaRootPath: $($SelectBootImage.Path)"
    #=================================================
    Step-BootImageIso
    #=================================================
    Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] End"
    #=================================================
}