From 19081a2e1fce12736964fcefbc15ae1f2d96eda5 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Tue, 18 Nov 2025 18:47:01 -0800 Subject: [PATCH] Skips empty driver folders during deployment Adds validation to filter out driver folders containing only WIM files or no installable content before attempting driver injection. This prevents unnecessary processing and potential errors when scanning driver repositories. Introduces a helper function to recursively check folders for installable driver content (non-WIM files). The validation runs before adding folders to the driver sources list, with appropriate logging when folders are skipped. Also includes minor code formatting improvements for consistency. --- .../WinPEDeployFFUFiles/ApplyFFU.ps1 | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index a3e9f95..affc9d4 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -711,7 +711,39 @@ function ConvertTo-ComparableModelName { } return $normalized } - + +function Test-DriverFolderHasInstallableContent { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string]$Path + ) + + if (-not (Test-Path -Path $Path -PathType Container)) { + return $false + } + + try { + $nonWimFile = Get-ChildItem -Path $Path -File -Recurse -ErrorAction Stop | Where-Object { + $extension = $_.Extension + if ([string]::IsNullOrWhiteSpace($extension)) { + return $true + } + return $extension.ToLowerInvariant() -ne '.wim' + } | Select-Object -First 1 + + if ($nonWimFile) { + return $true + } + + return $false + } + catch { + WriteLog "Failed to inspect driver folder '$Path': $($_.Exception.Message)" + return $false + } +} + #Get USB Drive and create log file $LogFileName = 'ScriptLog.txt' $USBDrive = Get-USBDrive @@ -1131,7 +1163,7 @@ if ($null -eq $DriverSourcePath) { try { $normalizedPath = [System.IO.Path]::GetFullPath($candidatePath) if ($normalizedPath.StartsWith($rootPath, [System.StringComparison]::OrdinalIgnoreCase)) { - $relativeSegment = $normalizedPath.Substring($rootPath.Length).TrimStart('\','/') + $relativeSegment = $normalizedPath.Substring($rootPath.Length).TrimStart('\', '/') if ([string]::IsNullOrWhiteSpace($relativeSegment)) { return Split-Path -Path $normalizedPath -Leaf } @@ -1158,6 +1190,10 @@ if ($null -eq $DriverSourcePath) { $childModelFolders = Get-ChildItem -Path $driverFolder.FullName -Directory -ErrorAction SilentlyContinue if (($childModelFolders.Count -gt 0) -and ($driverFolder.Parent.FullName -eq $driversRootFullPath)) { foreach ($modelFolder in $childModelFolders) { + if (-not (Test-DriverFolderHasInstallableContent -Path $modelFolder.FullName)) { + WriteLog "Skipping driver folder '$($modelFolder.FullName)' because no installable files were found." + continue + } $relativePath = & $relativePathResolver -candidatePath $modelFolder.FullName -rootPath $driversRootFullPath $DriverSources += [PSCustomObject]@{ Type = 'Folder' @@ -1167,6 +1203,10 @@ if ($null -eq $DriverSourcePath) { } } else { + if (-not (Test-DriverFolderHasInstallableContent -Path $driverFolder.FullName)) { + WriteLog "Skipping driver folder '$($driverFolder.FullName)' because no installable files were found." + continue + } $relativePath = & $relativePathResolver -candidatePath $driverFolder.FullName -rootPath $driversRootFullPath $DriverSources += [PSCustomObject]@{ Type = 'Folder' @@ -1199,7 +1239,7 @@ if ($null -eq $DriverSourcePath) { Path = $DriverSources[$i].Path } } - $displayArray | Format-Table -Property Number,Type,RelativePath,Path -AutoSize + $displayArray | Format-Table -Property Number, Type, RelativePath, Path -AutoSize do { try {