private/Step-BuildBootLogRegCurrentVersion.ps1

#Requires -PSEdition Core

function Step-BuildBootLogRegCurrentVersion {
    <#
    .SYNOPSIS
        Exports CurrentVersion registry metadata from the mounted WinPE image
 
    .DESCRIPTION
        Loads the mounted image's SOFTWARE hive under a temporary HKLM key and reads
        selected values from Windows NT\CurrentVersion. When the hive and key are
        available, it writes the selected values as text, CLIXML, and JSON under global
        BuildMedia.CorePath and displays the object through Out-Host.
 
        The hive is unloaded in a finally block. A missing SOFTWARE hive produces a
        warning and no export files.
 
    .EXAMPLE
        PS> Step-BuildBootLogRegCurrentVersion
 
        Exports and displays selected CurrentVersion values from the mounted image.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        None. Registry data is sent to the host and written to files.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: 2026-08-28
 
        Requires global BuildMedia.MountPath and BuildMedia.CorePath, reg.exe, and
        access to load the mounted SOFTWARE hive. Temporarily creates
        HKLM\OSDeployCoreMounted and writes three metadata files.
    #>

    [CmdletBinding()]
    param ()

    $MountPath = $global:BuildMedia.MountPath
    $CorePath = $global:BuildMedia.CorePath

    Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Export Registry CurrentVersion to $CorePath\winpe-regcurrentversion.json"

    $softwareHivePath = Join-Path $MountPath 'Windows\System32\Config\SOFTWARE'
    if (-not (Test-Path $softwareHivePath)) {
        Write-Warning "[$(Get-Date -Format s)] SOFTWARE hive not found at $softwareHivePath"
        return
    }

    $hiveName = 'OSDeployCoreMounted'
    try {
        reg.exe LOAD "HKLM\$hiveName" "$softwareHivePath" 2>&1 | Out-Null

        $regPath = "HKLM:\$hiveName\Microsoft\Windows NT\CurrentVersion"
        if (Test-Path $regPath) {
            $RegKeyCurrentVersion = Get-ItemProperty -Path $regPath -ErrorAction SilentlyContinue |
                Select-Object -Property CurrentBuild, CurrentBuildNumber, BuildLabEx,
                    CurrentVersion, EditionID, InstallationType, ProductName,
                    ReleaseId, UBR, DisplayVersion
            if ($RegKeyCurrentVersion) {
                $RegKeyCurrentVersion | Out-File "$CorePath\winpe-regcurrentversion.txt"
                $RegKeyCurrentVersion | Export-Clixml -Path "$CorePath\winpe-regcurrentversion.xml"
                $RegKeyCurrentVersion | ConvertTo-Json -Depth 5 | Out-File "$CorePath\winpe-regcurrentversion.json" -Encoding utf8 -Force
                $RegKeyCurrentVersion | Out-Host
            }
        }
    }
    finally {
        Start-Sleep -Seconds 3
        reg.exe UNLOAD "HKLM\$hiveName" 2>&1 | Out-Null
    }
}