private/Step-BuildBootSaveWindowsImage.ps1

#Requires -PSEdition Core

function Step-BuildBootSaveWindowsImage {
    <#
    .SYNOPSIS
        Saves changes to the mounted Windows image without dismounting it
 
    .DESCRIPTION
        Pipes global BuildMedia.WindowsImage to Save-WindowsImage and writes a
        timestamped servicing log under global BuildMedia.LogsPath. The mounted image
        remains mounted, and command output is suppressed.
 
        Terminating errors are reported as nonterminating errors so they do not abort
        the calling build.
 
    .EXAMPLE
        PS> Step-BuildBootSaveWindowsImage
 
        Commits current changes while leaving the Windows image mounted.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        None.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: 2026-08-28
 
        Requires global BuildMedia.WindowsImage and BuildMedia.LogsPath and the
        Save-WindowsImage cmdlet. Commits pending changes and creates a log file.
    #>

    [CmdletBinding()]
    param ()

    try {
    $LogsPath = $global:BuildMedia.LogsPath

    Write-HostDateTimeDarkGray 'Save Windows Image'
    $CurrentLog = "$LogsPath\$((Get-Date).ToString('yyMMdd-HHmmss'))-Save-WindowsImage.log"
    $global:BuildMedia.WindowsImage | Save-WindowsImage -LogPath $CurrentLog | Out-Null
    }
    catch {
        Write-Error -ErrorRecord $_ -ErrorAction Continue
    }
}