diff --git a/FFUDevelopment/Apps/Orchestration/Run-Sysprep.ps1 b/FFUDevelopment/Apps/Orchestration/Run-Sysprep.ps1 index a383765..8a36290 100644 --- a/FFUDevelopment/Apps/Orchestration/Run-Sysprep.ps1 +++ b/FFUDevelopment/Apps/Orchestration/Run-Sysprep.ps1 @@ -1,14 +1,18 @@ #The below lines will remove the unattend.xml that gets the machine into audit mode. If not removed, the OS will get stuck booting to audit mode each time. #Also kills the sysprep process in order to automate sysprep generalize -# Convert these commands to native powershell -# del c:\windows\panther\unattend\unattend.xml /F /Q -# del c:\windows\panther\unattend.xml /F /Q -# taskkill /IM sysprep.exe -# timeout /t 10 -# & c:\windows\system32\sysprep\sysprep.exe /quiet /generalize /oobe +Write-Host "Removing existing unattend.xml files and stopping sysprep process if running..." Remove-Item -Path "C:\windows\panther\unattend\unattend.xml" -Force -ErrorAction SilentlyContinue Remove-Item -Path "C:\windows\panther\unattend.xml" -Force -ErrorAction SilentlyContinue Stop-Process -Name "sysprep" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 10 -& "C:\windows\system32\sysprep\sysprep.exe" /quiet /generalize /oobe +# If an Unattend.xml has been provided on the mounted Apps ISO (D:\Unattend\Unattend.xml), +# pass it to sysprep; otherwise, run without /unattend. +$unattendOnAppsIso = "D:\Unattend\Unattend.xml" +if (Test-Path -Path $unattendOnAppsIso) { + Write-Host "Using $unattendOnAppsIso from Apps ISO..." + & "C:\windows\system32\sysprep\sysprep.exe" /quiet /generalize /oobe /unattend:$unattendOnAppsIso +} +else { + & "C:\windows\system32\sysprep\sysprep.exe" /quiet /generalize /oobe +} diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index f16671d..a3bff05 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -93,6 +93,9 @@ Prefix for the generated FFU file. Default is _FFU. .PARAMETER Headers Headers to use when downloading files. Not recommended to modify. +.PARAMETER InjectUnattend +When set to $true and InstallApps is also $true, copies unattend_[arch].xml from $FFUDevelopmentPath\unattend to $FFUDevelopmentPath\Apps\Unattend\Unattend.xml so sysprep can use it inside the VM. Default is $false. + .PARAMETER InstallApps When set to $true, the script will create an Apps.iso file from the $FFUDevelopmentPath\Apps folder. It will also create a VM, mount the Apps.iso, install the apps, sysprep, and capture the VM. When set to $false, the FFU is created from a VHDX file, and no VM is created. @@ -420,6 +423,7 @@ param( [string]$ConfigFile, [Parameter(Mandatory = $false)] [string]$ExportConfigFile, + [bool]$InjectUnattend = $false, [string]$orchestrationPath, [bool]$UpdateADK = $true, [bool]$CleanupCurrentRunDownloads = $false, @@ -5125,6 +5129,28 @@ if ($InstallApps) { } #Create Apps ISO + # Inject Unattend.xml into Apps if requested and applicable + if ($InstallApps -and $InjectUnattend) { + # Determine source unattend.xml based on architecture + $archSuffix = if ($WindowsArch -ieq 'arm64') { 'arm64' } else { 'x64' } + $unattendSource = Join-Path $UnattendFolder "unattend_$archSuffix.xml" + + # Ensure target folder exists under Apps + $targetFolder = Join-Path $AppsPath 'Unattend' + if (-not (Test-Path -Path $targetFolder -PathType Container)) { + New-Item -Path $targetFolder -ItemType Directory -Force | Out-Null + } + + # Copy if source exists; otherwise log and skip + if (Test-Path -Path $unattendSource -PathType Leaf) { + $destination = Join-Path $targetFolder 'Unattend.xml' + Copy-Item -Path $unattendSource -Destination $destination -Force | Out-Null + WriteLog "Injected unattend file into Apps: $unattendSource -> $destination" + } + else { + WriteLog "InjectUnattend is true but source file missing: $unattendSource. Skipping unattend injection." + } + } Set-Progress -Percentage 10 -Message "Creating Apps ISO..." WriteLog "Creating $AppsISO file" New-AppsISO diff --git a/FFUDevelopment/BuildFFUVM_UI.xaml b/FFUDevelopment/BuildFFUVM_UI.xaml index 5fb9c1e..af9b7d3 100644 --- a/FFUDevelopment/BuildFFUVM_UI.xaml +++ b/FFUDevelopment/BuildFFUVM_UI.xaml @@ -411,7 +411,8 @@