From 660a619944d967425ab2df8801d820122d9c16a1 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Fri, 27 Jun 2025 10:57:33 -0700 Subject: [PATCH] Improves driver matching to select the most specific rule Refines the driver selection logic to correctly handle overlapping or wildcard-based rules in the driver mapping file. Previously, the script would use the first rule that matched the system manufacturer and model. This could lead to a less specific rule being chosen if it appeared before a more specific one. The logic now finds all matching rules and selects the one with the most specific model name, ensuring a more accurate driver package is applied. --- .../WinPEDeployFFUFiles/ApplyFFU.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index 824c32c..73c672d 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -436,16 +436,26 @@ if (Test-Path -Path $driverMappingPath -PathType Leaf) { # Load and parse the mapping file $driverMappings = Get-Content -Path $driverMappingPath -Raw | ConvertFrom-Json - # Find a matching rule - $matchedRule = $null + # Find all matching rules and select the most specific one + $matchingRules = @() foreach ($rule in $driverMappings) { # Use -like for wildcard matching if ($systemManufacturer -like "$($rule.Manufacturer)*" -and $systemModel -like "$($rule.Model)*") { - $matchedRule = $rule - break + $matchingRules += $rule } } + # Select the best match + $matchedRule = $null + if ($matchingRules.Count -gt 0) { + WriteLog "Found $($matchingRules.Count) potential driver mapping rule(s)." + foreach ($rule in $matchingRules) { + WriteLog " - Potential Match: Manufacturer='$($rule.Manufacturer)', Model='$($rule.Model)', Path='$($rule.DriverPath)'" + } + # Sort by model name length, descending, to find the most specific match + $matchedRule = $matchingRules | Sort-Object -Property @{Expression = { $_.Model.Length } } -Descending | Select-Object -First 1 + } + if ($null -ne $matchedRule) { WriteLog "Automatic match found: Manufacturer='$($matchedRule.Manufacturer)', Model='$($matchedRule.Model)'" $potentialDriverPath = Join-Path -Path $DriversPath -ChildPath $matchedRule.DriverPath