private/Step-BuildBootLogWindowsPackage.ps1

#Requires -PSEdition Core

function Step-BuildBootLogWindowsPackage {
    <#
    .SYNOPSIS
        Exports and formats package metadata from the mounted Windows image
 
    .DESCRIPTION
        Gets packages from global BuildMedia.WindowsImage and, when results exist,
        exports full package properties as CLIXML and JSON under global
        BuildMedia.CorePath. It also sorts packages by name and writes a formatted
        table to the success stream.
 
    .EXAMPLE
        PS> Step-BuildBootLogWindowsPackage
 
        Writes package metadata files and emits a formatted package table.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Object. Emits PowerShell formatting records produced by Format-Table when packages exist.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: 2026-08-28
 
        Requires global BuildMedia.WindowsImage and BuildMedia.CorePath and the
        Get-WindowsPackage cmdlet. Writes winpe-windowspackage.xml and
        winpe-windowspackage.json when package records are returned.
    #>

    [CmdletBinding()]
    param ()

    $CorePath = $global:BuildMedia.CorePath

    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Export Get-WindowsPackage to $CorePath\winpe-windowspackage.json"
    $WindowsPackage = $global:BuildMedia.WindowsImage | Get-WindowsPackage
    if ($WindowsPackage) {
        $WindowsPackage | Select-Object * | Export-Clixml -Path "$CorePath\winpe-windowspackage.xml" -Force
        $WindowsPackage | ConvertTo-Json -Depth 5 | Out-File "$CorePath\winpe-windowspackage.json" -Encoding utf8 -Force
        $WindowsPackage | Sort-Object -Property PackageName | Format-Table -AutoSize
    }
}