Skip to content

Improve Make2023BootableMedia.ps1: auto-download oscdimg, path handling, boot.stl, NTFS enforcement#361

Merged
Flickdm merged 2 commits intomicrosoft:mainfrom
ballsop:feature/issue-333-download-oscdimg
Mar 14, 2026
Merged

Improve Make2023BootableMedia.ps1: auto-download oscdimg, path handling, boot.stl, NTFS enforcement#361
Flickdm merged 2 commits intomicrosoft:mainfrom
ballsop:feature/issue-333-download-oscdimg

Conversation

@ballsop
Copy link

@ballsop ballsop commented Mar 14, 2026

Description

  • Add Download-Oscdimg function to download oscdimg.exe from the Microsoft public symbol server when not found locally, with architecture detection (AMD64/ARM64/x86) and user confirmation prompt. Previously downloaded copies in %TEMP% are reused automatically. Addresses [Feature]: Make2023BootableMedia should have an option to download oscdimg if not present #333.

  • Fix path handling errors found in testing: normalize ISOPath to absolute early via ConvertTo-AbsolutePath to prevent crash when bare filenames are passed. Replace fragile Substring/LastIndexOf with Split-Path in Create-ISOMedia. Replace unsafe Substring(0,1) drive letter extraction with Split-Path -Qualifier in Initialize-StagingDirectory and Validate-Parameters. Add null/empty input guard and use TrimEnd in ConvertTo-AbsolutePath.

  • Copy boot.stl from boot.wim (Windows\Boot\EFI\boot.stl) to staged media (EFI\Microsoft\Boot\boot.stl) when present and not already at destination. Recent OS servicing introduced a new dependency on boot.stl.

  • Require NTFS for StagingDir and NewMediaPath since WIM mounting relies on reparse points not fully supported on ReFS.

  • Impacts functionality?

  • Impacts security?

  • Breaking change?

  • Includes tests?

  • Includes documentation?

How This Was Tested

Tested on ISO, USB, and LOCAL media creation flows on both X64 and ARM64 systems.

Integration Instructions

N/A

…ng, boot.stl, NTFS enforcement

- Add Download-Oscdimg function to download oscdimg.exe from the Microsoft
  public symbol server when not found locally, with architecture detection
  (AMD64/ARM64/x86) and user confirmation prompt. Previously downloaded
  copies in %TEMP% are reused automatically. Addresses microsoft#333.

- Fix path handling: normalize ISOPath to absolute early via
  ConvertTo-AbsolutePath to prevent crash when bare filenames are passed.
  Replace fragile Substring/LastIndexOf with Split-Path in Create-ISOMedia.
  Replace unsafe Substring(0,1) drive letter extraction with Split-Path
  -Qualifier in Initialize-StagingDirectory and Validate-Parameters.
  Add null/empty input guard and use TrimEnd in ConvertTo-AbsolutePath.

- Copy boot.stl from boot.wim (Windows\Boot\EFI\boot.stl) to staged media
  (EFI\Microsoft\Boot\boot.stl) when present and not already at destination.

- Require NTFS for StagingDir and NewMediaPath since WIM mounting relies on
  reparse points not fully supported on ReFS.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Windows media update PowerShell script to be more robust in real-world usage by improving dependency handling (oscdimg), fixing path normalization edge cases, and ensuring media staging works reliably with newer Windows boot requirements and filesystem constraints.

Changes:

  • Add Download-Oscdimg and prompt-driven fallback to download oscdimg.exe when missing.
  • Normalize and harden path handling (absolute ISOPath, safer Split-Path usage, drive qualifier parsing, null/empty guards).
  • Enforce NTFS for staging/LOCAL media paths and copy boot.stl from boot.wim when present.
Comments suppressed due to low confidence (1)

scripts/windows/Make2023BootableMedia.ps1:711

  • ConvertTo-AbsolutePath trims trailing backslashes and then returns early for any ^[a-zA-Z]: path. This turns a drive root like C:\ into C:, which in PowerShell is drive-relative (current directory on that drive) and can cause staging/output paths to resolve unexpectedly. Handle drive roots explicitly (e.g., normalize ^[A-Za-z]:\\?$ to X:\) and avoid returning drive-relative paths like C:foo without expanding them to a fully qualified path.
    $tmpPath = $Path.TrimEnd('\')

    # If a root drive path (C:\), return as-is
    if ($tmpPath -match "^[a-zA-Z]:") {
        return $tmpPath
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Replace Authenticode signature checks with SHA256 hash validation for
  downloaded and cached oscdimg.exe (binary is not Authenticode-signed on
  the symbol server). Known hashes defined once in global variable.
- Download to temp filename first, validate hash, then move into place
  to avoid partial/corrupt files at the final path.
- Cached copies in %TEMP% are hash-validated before reuse; invalid copies
  are deleted and the download prompt is shown instead.
- Change ADK URLs from http:// to https:// in user-facing messages.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Flickdm Flickdm requested review from Javagedes and apop5 March 14, 2026 15:37
@Flickdm Flickdm merged commit cf2e7df into microsoft:main Mar 14, 2026
2 checks passed
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.

4 participants