|
| 1 | +function Get-WindowsImageFromIso { |
| 2 | +<# |
| 3 | + .SYNOPSIS |
| 4 | + Lists Windows images available in a WIM file inside an ISO. |
| 5 | +
|
| 6 | + .DESCRIPTION |
| 7 | + Mounts the specified ISO, locates the WIM file, lists its contents using Get-WindowsImage, and then dismounts the ISO. |
| 8 | +
|
| 9 | + .PARAMETER Path |
| 10 | + The path to the ISO file containing the Windows image. |
| 11 | +
|
| 12 | + .EXAMPLE |
| 13 | + Get-WindowsImageFromIso -Path 'C:\Images\Win10.iso' |
| 14 | +
|
| 15 | + Lists the available Windows images in the WIM file inside the specified ISO. |
| 16 | +
|
| 17 | + .NOTES |
| 18 | + Author: WindowsImageTools Team |
| 19 | + Requires: Administrator privileges |
| 20 | +#> |
| 21 | + [CmdletBinding()] |
| 22 | + param ( |
| 23 | + [Parameter(Mandatory = $true, Position = 0, HelpMessage = 'Enter the path to the ISO file')] |
| 24 | + [ValidateNotNullOrEmpty()] |
| 25 | + [ValidateScript({ Test-Path $_ })] |
| 26 | + [string]$Path |
| 27 | + ) |
| 28 | + |
| 29 | + $mountResult = Mount-DiskImage -ImagePath $Path -PassThru |
| 30 | + $driveLetter = ($mountResult | Get-Volume).DriveLetter |
| 31 | + if (-not $driveLetter) { |
| 32 | + throw "Failed to get drive letter for mounted ISO." |
| 33 | + } |
| 34 | + $mountedPath = $driveLetter + ":\" |
| 35 | + |
| 36 | + $wimFiles = Get-ChildItem -Path $mountedPath -Filter *.wim -Recurse |
| 37 | + if ($wimFiles.Count -eq 0) { |
| 38 | + Dismount-DiskImage -ImagePath $Path |
| 39 | + throw "No WIM files found in mounted ISO." |
| 40 | + } |
| 41 | + foreach ($wim in $wimFiles) { |
| 42 | + Write-Host "Listing images in $($wim.FullName):" |
| 43 | + Get-WindowsImage -ImagePath $wim.FullName |
| 44 | + } |
| 45 | + Dismount-DiskImage -ImagePath $Path |
| 46 | +} |
0 commit comments