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.
This commit is contained in:
rbalsleyMSFT
2026-04-28 13:10:48 -07:00
parent 8774fb4ef0
commit e1c6259021
@@ -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) {