Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions functions/private/Invoke-WinUtilISO.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,34 @@ function Invoke-WinUtilISOCleanAndReset {
$script.BeginInvoke()
}

function Get-WinUtilOSCDImgPath {
# Windows ADK installation
$oscdimg = Get-ChildItem "C:\Program Files (x86)\Windows Kits" -Recurse -Filter "oscdimg.exe" -ErrorAction SilentlyContinue |
Select-Object -First 1 -ExpandProperty FullName
if (-not $oscdimg) {
# Per-user winget installation
$oscdimg = Get-ChildItem "$env:LOCALAPPDATA\Microsoft\WinGet\Packages" -Recurse -Filter "oscdimg.exe" -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -match 'Microsoft\.OSCDIMG' } |
Select-Object -First 1 -ExpandProperty FullName
}

if (-not $oscdimg) {
# Installation available through the current process PATH
$oscdimg = Get-Command oscdimg.exe -CommandType Application -ErrorAction SilentlyContinue |
Select-Object -First 1 -ExpandProperty Source
}

if (-not $oscdimg) {
# WinGet links that may not yet be available through the current process PATH
$oscdimg = @(
"$env:LOCALAPPDATA\Microsoft\WinGet\Links\oscdimg.exe"
"$env:ProgramFiles\WinGet\Links\oscdimg.exe"
) | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return $oscdimg
}

function Invoke-WinUtilISOExport {
$contentsDir = $sync["Win11ISOContentsDir"]

Expand All @@ -551,14 +579,7 @@ function Invoke-WinUtilISOExport {

$outputISO = $dlg.FileName

# Locate oscdimg.exe (Windows ADK or winget per-user install)
$oscdimg = Get-ChildItem "C:\Program Files (x86)\Windows Kits" -Recurse -Filter "oscdimg.exe" |
Select-Object -First 1 -ExpandProperty FullName
if (-not $oscdimg) {
$oscdimg = Get-ChildItem "$env:LOCALAPPDATA\Microsoft\WinGet\Packages" -Recurse -Filter "oscdimg.exe" |
Where-Object { $_.FullName -match 'Microsoft\.OSCDIMG' } |
Select-Object -First 1 -ExpandProperty FullName
}
$oscdimg = Get-WinUtilOSCDImgPath

if (-not $oscdimg) {
Write-WinUtilISOLog "oscdimg.exe not found. Attempting to install via winget..."
Expand All @@ -569,9 +590,7 @@ function Invoke-WinUtilISOExport {
$winget = Get-Command winget
$result = & $winget install -e --id Microsoft.OSCDIMG --accept-package-agreements --accept-source-agreements
Write-WinUtilISOLog "winget output: $result"
$oscdimg = Get-ChildItem "$env:LOCALAPPDATA\Microsoft\WinGet\Packages" -Recurse -Filter "oscdimg.exe" |
Where-Object { $_.FullName -match 'Microsoft\.OSCDIMG' } |
Select-Object -First 1 -ExpandProperty FullName
$oscdimg = Get-WinUtilOSCDImgPath
} catch {
Write-WinUtilISOLog "winget not available or install failed: $_"
}
Expand Down