private/BootMedia/Steps/Get-OSDeployCoreWinRESource.ps1
|
#Requires -PSEdition Core function Get-OSDeployCoreWinRESource { <# .SYNOPSIS Enumerates imported WinRE sources from the OSDeployCore sources directory. .DESCRIPTION Scans the cache\windows-re directory for imported WinRE images and returns objects with metadata for each valid source. .PARAMETER Architecture Filter results by architecture (amd64 or arm64). .NOTES Author: David Segura Version: 0.1.0 #> [CmdletBinding()] param ( [ValidateSet('amd64', 'arm64')] [System.String] $Architecture ) $sourcePath = Join-Path $Script:OSDeployCorePath 'cache' 'windows-re' if (-not (Test-Path -Path $sourcePath)) { Write-Warning "WinRE sources directory not found: $sourcePath" return $null } # Search all subdirectories for properties.json files $propertiesFiles = Get-ChildItem -Path $sourcePath -Filter 'properties.json' -Recurse -File -ErrorAction SilentlyContinue if (@($propertiesFiles).Count -eq 0) { Write-Warning "No imported WinRE sources found in $sourcePath" Write-Warning "Mount a Windows 25H2 ISO and run Import-OSDeployOS to import WinRE." return $null } $results = foreach ($propertiesFile in $propertiesFiles) { try { $props = Get-Content -Path $propertiesFile.FullName -Raw | ConvertFrom-Json } catch { Write-Warning "Could not read $($propertiesFile.FullName)" continue } $itemDir = $propertiesFile.Directory.FullName $itemName = if ($props.Name) { $props.Name } else { $propertiesFile.Directory.Name } $itemArch = if ($props.Architecture) { $props.Architecture } else { 'unknown' } # Resolve ImagePath from properties or discover winre.wim $itemImagePath = if ($props.ImagePath -and (Test-Path -Path $props.ImagePath)) { $props.ImagePath } elseif (Test-Path (Join-Path $itemDir '.wim' 'winre.wim')) { Join-Path $itemDir '.wim' 'winre.wim' } elseif (Test-Path (Join-Path $itemDir 'winre.wim')) { Join-Path $itemDir 'winre.wim' } else { Write-Warning "No winre.wim found for $itemName in $itemDir" continue } # Flatten properties.json fields into the output object for GridView display [PSCustomObject][ordered]@{ Type = if ($props.Type) { $props.Type } else { 'WinRE' } Id = if ($props.Id) { $props.Id } else { $itemName } Name = $itemName CreatedTime = $props.CreatedTime ModifiedTime = $props.ModifiedTime InstallationType = $props.InstallationType Version = $props.Version Architecture = $itemArch Languages = if ($props.Languages) { $props.Languages -join ',' } else { '' } ImageSize = $props.ImageSize DirectoryCount = $props.DirectoryCount FileCount = $props.FileCount ImageName = $props.ImageName OSImageName = $props.OSImageName OSEditionId = $props.OSEditionId OSVersion = $props.OSVersion OSCreatedTime = $props.OSCreatedTime OSModifiedTime = $props.OSModifiedTime Path = $itemDir ImagePath = $itemImagePath ImageIndex = if ($props.ImageIndex) { $props.ImageIndex } else { 1 } } } if ($Architecture -and $results) { $results = $results | Where-Object { $_.Architecture -eq $Architecture } } $results | Sort-Object -Property Name } |