From 9f6ea0fb5807166fad07998ee74c66ed5abbbc06 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Thu, 10 Jul 2025 12:24:49 -0700 Subject: [PATCH] Improve driver injection by mounting WIMs Replaces the slow WIM extraction process with a faster WIM mount operation. This significantly improves performance when injecting drivers from a WIM file. The script now properly unmounts the WIM after injection to ensure resources are cleaned up correctly. Additionally, log messages are now written to the console for better real-time feedback during script execution. --- FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index 39c3066..61e2086 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -47,6 +47,7 @@ function Get-HardDrive() { function WriteLog($LogText) { Add-Content -path $LogFile -value "$((Get-Date).ToString()) $LogText" + Write-Host $LogText } function Set-DiskpartAnswerFiles($DiskpartFile, $DiskID) { @@ -760,10 +761,10 @@ if ($null -ne $DriverSourcePath) { WriteLog "Creating temporary directory for drivers at $TempDriverDir" New-Item -Path $TempDriverDir -ItemType Directory -Force | Out-Null - WriteLog "Extracting WIM contents to $TempDriverDir" - Write-Warning 'Extracting Drivers from WIM - dism will pop a window with no progress. This can take a few minutes to complete. Please be patient.' - Invoke-Process dism.exe "/Apply-Image /ImageFile:""$DriverSourcePath"" /Index:1 /ApplyDir:""$TempDriverDir""" - WriteLog "WIM extraction successful." + WriteLog "Mounting WIM contents to $TempDriverDir" + # For some reason can't use /mount-image with invoke-process, so using dism.exe directly + dism.exe /Mount-Image /ImageFile:$DriverSourcePath /Index:1 /MountDir:$TempDriverDir /ReadOnly /optimize + WriteLog "WIM mount successful." WriteLog "Injecting drivers from $TempDriverDir" Write-Warning 'Injecting Drivers from WIM - dism will pop a window with no progress. This can take a few minutes to complete. Please be patient.' @@ -779,6 +780,9 @@ if ($null -ne $DriverSourcePath) { } finally { if (Test-Path -Path $TempDriverDir) { + WriteLog "Unmounting WIM from $TempDriverDir" + Invoke-Process dism.exe "/Unmount-Image /MountDir:""$TempDriverDir"" /Discard" + WriteLog "Unmount successful." WriteLog "Cleaning up temporary driver directory: $TempDriverDir" Remove-Item -Path $TempDriverDir -Recurse -Force WriteLog "Cleanup successful."