From e1c62590218736bb238d92bd697936c8ba93de69 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Tue, 28 Apr 2026 13:10:48 -0700 Subject: [PATCH] Processes unattend from a temp copy Copies the source answer file to local temp storage before use, preserving the original media file and failing fast if the working copy cannot be prepared. --- .../WinPEDeployFFUFiles/ApplyFFU.ps1 | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index 49b93ba..2eb50ab 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -1092,13 +1092,24 @@ if (Test-Path -Path $PPKGFolder) { #FindUnattend $UnattendFolder = $USBDrive + "unattend\" -$UnattendFilePath = $UnattendFolder + "unattend.xml" +$UnattendSourceFilePath = $UnattendFolder + "unattend.xml" +$UnattendWorkingFilePath = Join-Path -Path $env:TEMP -ChildPath 'unattend.xml' $UnattendPrefixPath = $UnattendFolder + "prefixes.txt" $UnattendComputerNamePath = $UnattendFolder + "SerialComputerNames.csv" -If (Test-Path -Path $UnattendFilePath) { - $UnattendFile = Get-ChildItem -Path $UnattendFilePath - If ($UnattendFile) { - $Unattend = $true +If (Test-Path -Path $UnattendSourceFilePath) { + $UnattendSourceFile = Get-ChildItem -Path $UnattendSourceFilePath + If ($UnattendSourceFile) { + try { + WriteLog "Copying source unattend file $($UnattendSourceFile.FullName) to temporary working file $UnattendWorkingFilePath" + Copy-Item -Path $UnattendSourceFile.FullName -Destination $UnattendWorkingFilePath -Force -ErrorAction Stop + $UnattendFile = Get-ChildItem -Path $UnattendWorkingFilePath -ErrorAction Stop + WriteLog "Using temporary unattend working file $($UnattendFile.FullName)" + $Unattend = $true + } + catch { + WriteLog "Copying source unattend file to temporary working file failed with error: $_" + Stop-Script -Message "Copying source unattend file to temporary working file failed with error: $_" + } } } If (Test-Path -Path $UnattendPrefixPath) {