private/BootMedia/WindowsOS/Get-MountedWindowsImageIndex.ps1
|
#Requires -Version 7.4 function Get-MountedWindowsImageIndex { <# .SYNOPSIS Returns Windows image index information from mounted installation media. .DESCRIPTION Calls Find-MountedWindowsMedia to locate install.wim or install.esd files on mounted drives, then enumerates image indexes via Get-WindowsImage. Architecture numeric codes are translated to human-readable strings (amd64, arm64, etc.). Results can optionally be presented in an Out-GridView picker. .PARAMETER GridView Selects the Out-GridView output mode. Use 'Single' for single selection or 'Multiple' for multi-selection. When omitted, all results are returned without a picker. .OUTPUTS [PSCustomObject] Selected image index objects with MediaRoot, ImagePath, ImageIndex, ImageName, Architecture, and other DISM metadata. .NOTES Author: David Segura Version: 0.1.0 #> [CmdletBinding()] param ( [Parameter()] [ValidateSet('Single', 'Multiple')] [string]$GridView ) $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $IsAdmin) { Write-Warning "[$($MyInvocation.MyCommand.Name)] Must be run with Administrator privileges" return } $PSDriveWindowsImageFile = Find-MountedWindowsMedia if (-not $PSDriveWindowsImageFile) { return $null } $WindowsMediaImages = $PSDriveWindowsImageFile | ForEach-Object { $MediaRoot = $_.MediaRoot $ImageFilePath = $_.FullName Write-OSDeployCoreProgress "WindowsImage: $ImageFilePath" # Use cache to avoid expensive DISM calls on repeated runs $CachedImages = Get-WimIndexCache -ImagePath $ImageFilePath foreach ($cachedImage in $CachedImages) { $cachedImage | Select-Object -Property @{Name = 'MediaRoot'; Expression = { $MediaRoot } }, * } } # Translate Architecture numeric codes to human-readable strings foreach ($Image in $WindowsMediaImages) { switch ($Image.Architecture) { '0' { $Image.Architecture = 'x86' } '1' { $Image.Architecture = 'MIPS' } '2' { $Image.Architecture = 'Alpha' } '3' { $Image.Architecture = 'PowerPC' } '5' { $Image.Architecture = 'ARM' } '6' { $Image.Architecture = 'ia64' } '9' { $Image.Architecture = 'amd64' } '12' { $Image.Architecture = 'arm64' } } } $Results = $WindowsMediaImages | Select-Object -Property MediaRoot, ImagePath, ImageIndex, ImageName, Architecture, Version, EditionId, Languages, InstallationType, CreatedTime, ModifiedTime, DirectoryCount, FileCount, ImageDescription, ImageSize, ImageType, WIMBoot, ProductName, Hal, ProductSuite, ProductType, MajorVersion, MinorVersion, Build, SPBuild, SPLevel, ImageBootable, SystemRoot, DefaultLanguageIndex, LogPath, ScratchDirectory, LogLevel if ($GridView) { $Results = $Results | Out-GridView -Title 'Select a WindowsImage and press OK (Cancel to Exit)' -OutputMode $GridView } return $Results } |