Skip to content

Instantly share code, notes, and snippets.

@ConnerWill
Created September 5, 2024 16:32
Show Gist options
  • Save ConnerWill/ca931ff18d712654dc430089c29c57a2 to your computer and use it in GitHub Desktop.
Save ConnerWill/ca931ff18d712654dc430089c29c57a2 to your computer and use it in GitHub Desktop.
Script to modify a WinPE ISO to prevent the 'Press Any Key To Boot From...' prompt for UEFI deployments.
<#
.SYNOPSIS
Script to modify a WinPE ISO to prevent the "Press Any Key To Boot From..." prompt for UEFI deployments.
.DESCRIPTION
Script to modify a WinPE ISO to prevent the "Press Any Key To Boot From..." prompt for UEFI deployments.
Modified from: https://www.deploymentresearch.com/a-good-iso-file-is-a-quiet-iso-file
.NOTES
Requires Windows ADK 10 to be installed.
.PARAMETER WinPE_Architecture
The architecture of the WinPE image. Default is "amd64". Valid values are "amd64" or "x86".
Parameter Alias: arch
.PARAMETER WinPE_InputISOfile
The path to the input WinPE ISO file. Default is "${env:SystemDrive}\ISO\Zero Touch WinPE 10 x64.iso".
Parameter Alias: input
.PARAMETER WinPE_OutputISOfile
The path for the output WinPE ISO file. Default is "${env:SystemDrive}\ISO\Zero Touch WinPE 10 x64 - NoPrompt.iso".
Parameter Alias: output
.PARAMETER ADK_Path
The path to the Windows ADK installation. Default is "${env:SystemDrive}\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit".
Parameter Alias: adk
.PARAMETER TempFolder
The path to temporary folder for extraction. Default is "${env:SystemDrive}\Temp\ISO".
Parameter Alias: tempdir
.EXAMPLE
Run script and specifying paths in parameters
.\Create-NoPromptISO.ps1 -WinPE_Architecture amd64 -WinPE_InputISOfile "${env:SystemDrive}\ISO\Zero Touch WinPE 10 x64.iso" -WinPE_OutputISOfile "${env:SystemDrive}\ISO\Zero Touch WinPE 10 x64 - NoPrompt.iso" -ADK_Path "${env:SystemDrive}\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit" -TempFolder "${env:SystemDrive}\Temp\ISO"
.EXAMPLE
Short form, using parameter aliases
.\Create-NoPromptISO.ps1 -arch x86 -input "D:\WinPE.iso" -output "D:\WinPE-NoPrompt.iso" -adk "D:\ADK" -tempdir "D:\temp\iso"
.EXAMPLE
Run script using default parameters
.\Create-NoPromptISO.ps1
#>
param (
[Alias("arch")]
[Parameter(Mandatory=$false)]
[string]$WinPE_Architecture = "amd64",
[Alias("input")]
[Parameter(Mandatory=$false)]
[string]$WinPE_InputISOfile = "${env:SystemDrive}\ISO\Zero Touch WinPE 10 x64.iso",
[Alias("output")]
[Parameter(Mandatory=$false)]
[string]$WinPE_OutputISOfile = "${env:SystemDrive}\ISO\Zero Touch WinPE 10 x64 - NoPrompt.iso",
[Alias("adk")]
[Parameter(Mandatory=$false)]
[string]$ADK_Path = "${env:SystemDrive}\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit",
[Alias("tempdir")]
[Parameter(Mandatory=$false)]
[string]$TempFolder = "${env:SystemDrive}\Temp\ISO"
)
# Validate locations
if (!(Test-Path $WinPE_InputISOfile)) {
Write-Warning "WinPE Input ISO file does not exist, aborting..."
return
}
if (!(Test-Path $ADK_Path)) {
Write-Warning "ADK Path does not exist, aborting..."
return
}
$WinPE_ADK_Path = Join-Path -Path $ADK_Path -ChildPath "Windows Preinstallation Environment"
$OSCDIMG_Path = Join-Path -Path $ADK_Path -ChildPath "Deployment Tools\${WinPE_Architecture}"
if (!(Test-Path $WinPE_ADK_Path)) {
Write-Warning "WinPE ADK Path does not exist, aborting..."
return
}
if (!(Test-Path $OSCDIMG_Path)) {
Write-Warning "OSCDIMG Path does not exist, aborting..."
return
}
# Mount the original ISO (WinPE_InputISOfile) and figure out the drive letter
Mount-DiskImage -ImagePath $WinPE_InputISOfile
$ISOImage = Get-DiskImage -ImagePath $WinPE_InputISOfile | Get-Volume
$ISODrive = "$($ISOImage.DriveLetter):\"
# Prepare temporary folder for extraction
if (!(Test-Path $TempFolder)) {
New-Item -Path $TempFolder -ItemType Directory -Force
}
# Copy ISO contents to temporary folder
Copy-Item -Path "${ISODrive}\*" -Destination $TempFolder -Recurse
Remove-Item -Path (Join-Path -Path $TempFolder -ChildPath "boot\bootfix.bin") -Force
# Dismount the original ISO
Dismount-DiskImage -ImagePath $WinPE_InputISOfile
# Create a new bootable WinPE ISO file with modified boot data
# https://learn.microsoft.com/en-us/troubleshoot/windows-server/setup-upgrade-and-drivers/create-iso-image-for-uefi-platforms
$BootData = '2#p0,e,b"{0}"#pEF,e,b"{1}"' -f (Join-Path -Path $OSCDIMG_Path -ChildPath "etfsboot.com"), (Join-Path -Path $OSCDIMG_Path -ChildPath "efisys_noprompt.bin")
$Proc = Start-Process -FilePath (Join-Path -Path $OSCDIMG_Path -ChildPath "oscdimg.exe") -ArgumentList @("-bootdata:$BootData", '-u2', '-udfver102', "${TempFolder}\", "`"${WinPE_OutputISOfile}`"") -PassThru -Wait -NoNewWindow
if ($Proc.ExitCode -ne 0) {
Throw "Failed to generate ISO with exit code: $($Proc.ExitCode)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment