Skip to content

Fix Start-OSDCloud -ZTI blocking on image index prompt with -FindImageFile - #383

Open
kristofferkhansen wants to merge 2 commits into
OSDeploy:masterfrom
kristofferkhansen:fix/zti-imageindex-prompt
Open

Fix Start-OSDCloud -ZTI blocking on image index prompt with -FindImageFile#383
kristofferkhansen wants to merge 2 commits into
OSDeploy:masterfrom
kristofferkhansen:fix/zti-imageindex-prompt

Conversation

@kristofferkhansen

@kristofferkhansen kristofferkhansen commented Aug 17, 2026

Copy link
Copy Markdown

Fixes #287

Problem

Start-OSDCloud -FindImageFile -ZTI still blocks on interactive prompts, defeating fully zero-touch deployments. The only known workaround is piping stdin to answer them, e.g.:

cmd /c 'echo 1 | powershell -command Start-OSDCloud -Restart -ZTI -FindImageFile -SkipAutopilot -SkipODT'

Two unguarded prompts are involved:

  1. Select-OSDCloudFileWim — always prompts to pick a WIM/ESD/SWM file under \OSDCloud\OS\, even with a single candidate. On closed/EOF stdin, Read-Host returns '', and '' -ge 0 evaluates false, so the do/until loop spins forever instead of failing.
  2. Select-OSDCloudImageIndex — always prompts to pick an image index whenever the selected WIM contains more than one image.

Fix

  • Select-OSDCloudFileWim.ps1: add a -ZTI switch. With exactly one file candidate, auto-select it. With more than one, throw immediately rather than guessing which image to deploy or hanging on a starved prompt — picking the wrong file is worse than picking the wrong index within a file, so this deliberately does not auto-pick the first result.
  • Select-OSDCloudImageIndex.ps1: add a -ZTI switch. Auto-return the first image index instead of prompting (matches the value the community echo 1 workaround was already manually supplying).
  • Start-OSDCloud.ps1: pass -ZTI:$Global:StartOSDCloud.ZTI at both call sites in the -FindImageFile path.

This mirrors the existing $Global:StartOSDCloud.ZTI short-circuit pattern already used elsewhere in Start-OSDCloud.ps1 to skip prompts in ZTI mode.

Start-OSDCloudCLI.ps1's call site for Select-OSDCloudImageIndex is untouched (no -ZTI param passed), so its interactive behavior is unaffected.

Test plan

  • Parser.ParseFile on all changed files — no syntax errors
  • Mocked Get-WindowsImage returning 2 images: Select-OSDCloudImageIndex -ZTI returns the first index (1) with no prompt
  • Mocked single-image case: unchanged short-circuit behavior (still returns without prompting)
  • Mocked Find-OSDCloudFile returning 1 candidate: Select-OSDCloudFileWim -ZTI auto-selects it with no prompt
  • Mocked Find-OSDCloudFile returning 2 candidates: Select-OSDCloudFileWim -ZTI throws immediately instead of hanging or guessing
  • Real WinPE Start-OSDCloud -Restart -ZTI -FindImageFile -SkipAutopilot -SkipODT run against real media (not verified in this environment — no WinPE available)

After this fix, the original command works without the echo 1 stdin workaround:

Start-OSDCloud -Restart -ZTI -FindImageFile -SkipAutopilot -SkipODT

…eFile

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.
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.
@kristofferkhansen

Copy link
Copy Markdown
Author

Tested ok on my side.

@kristofferkhansen

Copy link
Copy Markdown
Author

Cross-referencing #259, which addresses part of the same problem — it auto-selects the WIM in Select-OSDCloudFileWim when there's exactly one candidate, so there's been demand for unattended -FindImageFile for a while.

Differences in scope:

  • Update Select-OSDCloudFileWim.ps1 #259 changes behavior for all runs (interactive included) and covers only the file prompt. A -ZTI run still blocks on Select-OSDCloudImageIndex when the selected WIM contains more than one image, and with several file candidates the prompt still hangs on closed stdin.
  • This PR gates everything behind -ZTI (interactive behavior untouched), guards both prompts, and with several file candidates fails fast with a clear error instead of hanging or guessing.

If this merges, #259 could be closed as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full unattend / true ZTI Start-OSDCloud with offline wim

1 participant