private/BootMedia/Steps/Step-BootImageRegCurrentVersion.ps1

#Requires -PSEdition Core

function Step-BootImageRegCurrentVersion {
    <#
    .SYNOPSIS
        Exports Windows NT CurrentVersion registry information from the mounted WinPE image.
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

    [CmdletBinding()]
    param ()

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

    Write-OSDeployCoreProgress "Export Registry CurrentVersion to $CorePath\winpe-regcurrentversion.json"

    $softwareHivePath = Join-Path $MountPath 'Windows\System32\Config\SOFTWARE'
    if (-not (Test-Path $softwareHivePath)) {
        Write-Warning "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
    }
}