From 55fcf938c9d33866cd5806bc252d3a76843cf2f2 Mon Sep 17 00:00:00 2001 From: Kristoffer Konstad Hansen Date: Mon, 17 Aug 2026 17:50:09 +0200 Subject: [PATCH 1/2] Fix Start-OSDCloud -ZTI blocking on image index prompt with -FindImageFile Select-OSDCloudImageIndex always called Read-Host to pick an image index when a WIM contained more than one image, even when -ZTI was specified. This forced Start-OSDCloud -FindImageFile -ZTI into an interactive prompt during otherwise zero-touch deployments, requiring a stdin-piping workaround to answer it non-interactively. Select-OSDCloudImageIndex now accepts -ZTI and auto-selects the first image index (matching the existing ZTI defaulting pattern used elsewhere in Start-OSDCloud) instead of prompting. --- Public/OSDCloudTS/Select-OSDCloudImageIndex.ps1 | 7 ++++++- Public/Start-OSDCloud.ps1 | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Public/OSDCloudTS/Select-OSDCloudImageIndex.ps1 b/Public/OSDCloudTS/Select-OSDCloudImageIndex.ps1 index dad301028..cd30783bb 100644 --- a/Public/OSDCloudTS/Select-OSDCloudImageIndex.ps1 +++ b/Public/OSDCloudTS/Select-OSDCloudImageIndex.ps1 @@ -1,7 +1,8 @@ function Select-OSDCloudImageIndex { [CmdletBinding()] param ( - [string]$ImagePath + [string]$ImagePath, + [switch]$ZTI ) $Results = Get-WindowsImage -ImagePath $ImagePath @@ -14,6 +15,10 @@ function Select-OSDCloudImageIndex { if ($Results) { $Results | Select-Object -Property ImageIndex, ImageName | Format-Table | Out-Host + if ($ZTI) { + Return $Results[0].ImageIndex + } + do { $SelectReadHost = Read-Host -Prompt "Select an Image to apply by ImageIndex [Number]" } diff --git a/Public/Start-OSDCloud.ps1 b/Public/Start-OSDCloud.ps1 index 62302ffc9..030eec0fa 100644 --- a/Public/Start-OSDCloud.ps1 +++ b/Public/Start-OSDCloud.ps1 @@ -389,7 +389,7 @@ function Start-OSDCloud { $Global:StartOSDCloud.ImageFileItem = Select-OSDCloudFileWim if ($Global:StartOSDCloud.ImageFileItem) { - $Global:StartOSDCloud.OSImageIndex = Select-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName + $Global:StartOSDCloud.OSImageIndex = Select-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName -ZTI:$Global:StartOSDCloud.ZTI Write-Host -ForegroundColor DarkGray "ImageFileItem: $($Global:StartOSDCloud.ImageFileItem.FullName)" Write-Host -ForegroundColor DarkGray "OSImageIndex: $($Global:StartOSDCloud.OSImageIndex)" From c7e35baae29ac644ee5c299b9f580a5ef4df94f5 Mon Sep 17 00:00:00 2001 From: Kristoffer Konstad Hansen Date: Mon, 17 Aug 2026 19:08:54 +0200 Subject: [PATCH 2/2] Guard Select-OSDCloudFileWim's file-selection prompt with -ZTI too Select-OSDCloudFileWim always called Read-Host to pick a WIM/ESD/SWM file under \OSDCloud\OS\, even with only one candidate present and even when -ZTI was set. On closed/EOF stdin, Read-Host returns '', and '' -ge 0 evaluates false, so the do/until loop spins forever instead of failing. In practice this is currently masked by piping a literal "1" into stdin, which is fragile: it silently answers a different question if a second qualifying image ever lands in \OSDCloud\OS\. Select-OSDCloudFileWim now accepts -ZTI. With exactly one candidate it auto-selects it (matching the existing single-index short-circuit in Select-OSDCloudImageIndex). With more than one candidate, it throws immediately instead of guessing which image to deploy or hanging on a starved prompt - picking the wrong file is worse than picking the wrong image index within a file, so this deliberately does not auto-pick the first result the way Select-OSDCloudImageIndex does. Start-OSDCloud.ps1 now passes -ZTI:$Global:StartOSDCloud.ZTI at the call site, same as the prior Select-OSDCloudImageIndex fix. --- Public/OSDCloudTS/Select-OSDCloudFileWim.ps1 | 11 ++++++++++- Public/Start-OSDCloud.ps1 | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Public/OSDCloudTS/Select-OSDCloudFileWim.ps1 b/Public/OSDCloudTS/Select-OSDCloudFileWim.ps1 index 5bca3f254..6f4f0e1ed 100644 --- a/Public/OSDCloudTS/Select-OSDCloudFileWim.ps1 +++ b/Public/OSDCloudTS/Select-OSDCloudFileWim.ps1 @@ -10,7 +10,9 @@ https://github.com/OSDeploy/OSD/tree/master/docs #> function Select-OSDCloudFileWim { [CmdletBinding()] - param () + param ( + [switch]$ZTI + ) $i = $null $Results = @() @@ -34,6 +36,13 @@ function Select-OSDCloudFileWim { $Results | Select-Object -Property Selection, Name, Directory | Format-Table | Out-Host + if ($ZTI) { + if (($Results | Measure-Object).Count -eq 1) { + Return Get-Item (Join-Path $Results.Directory $Results.Name) + } + throw "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] -ZTI requires exactly one Windows Image candidate under \OSDCloud\OS\, found $(($Results | Measure-Object).Count). Remove the extras or run without -ZTI to select interactively." + } + do { $SelectReadHost = Read-Host -Prompt "Select a Windows Image to apply by Selection [Number]" } diff --git a/Public/Start-OSDCloud.ps1 b/Public/Start-OSDCloud.ps1 index 030eec0fa..97a795528 100644 --- a/Public/Start-OSDCloud.ps1 +++ b/Public/Start-OSDCloud.ps1 @@ -386,7 +386,7 @@ function Start-OSDCloud { Write-Host -ForegroundColor DarkGray "OSImageIndex: $($Global:StartOSDCloud.OSImageIndex)" } if ($PSBoundParameters.ContainsKey('FindImageFile')) { - $Global:StartOSDCloud.ImageFileItem = Select-OSDCloudFileWim + $Global:StartOSDCloud.ImageFileItem = Select-OSDCloudFileWim -ZTI:$Global:StartOSDCloud.ZTI if ($Global:StartOSDCloud.ImageFileItem) { $Global:StartOSDCloud.OSImageIndex = Select-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName -ZTI:$Global:StartOSDCloud.ZTI