From 50713188bffcb64f1b0c1f9eb89e02a300e3de98 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Thu, 11 Sep 2025 18:15:51 -0700 Subject: [PATCH] Refactor: Improve model name normalization for driver mapping Enhances the model name normalization function to better handle variations in hardware model strings. This change introduces specific rules to canonicalize "All-in-One" and screen size variants (e.g., "-in" or "inch") for more reliable matching against driver mapping rules. Additionally, optimizes performance by normalizing the system model once before the comparison loop. Logging is also added to show the original and normalized model strings for easier debugging. --- .../WinPEDeployFFUFiles/ApplyFFU.ps1 | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index 159d687..1bb6e68 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -209,10 +209,23 @@ function ConvertTo-ComparableModelName { param( [string]$Text ) - # Normalize model strings by converting any non-alphanumeric sequence to a single space, collapsing whitespace, and trimming. + # Normalize model strings with HP-specific adjustments. + # Remove inch unit variants (23.8-in, 23.8 inch, 23inch, 23-in, etc.) keeping only the numeric size. + # Canonicalize All-in-One variants (All in One, All-in-One, All-in-One PC, AiO, AIO) to 'AIO'. + # Convert any non-alphanumeric sequence to a single space, collapse whitespace, and trim. if ($null -eq $Text) { return '' } + $original = $Text + # Remove inch unit variants while preserving the numeric size + $Text = [regex]::Replace($Text, '(?i)(\d+(?:\.\d+)?)(?:\s*[-]?\s*)(?:in|inch)\b', '$1') + # Canonicalize All-in-One variants + $Text = [regex]::Replace($Text, '(?i)\bAll[\s-]*in[\s-]*One(?:\s*PC)?\b', 'AIO') + $Text = [regex]::Replace($Text, '(?i)\bAiO\b', 'AIO') + # Generic normalization $normalized = ($Text -replace '[^A-Za-z0-9]+', ' ') $normalized = ($normalized -replace '\s+', ' ').Trim() + if ($normalized -ne $original) { + WriteLog "Normalized model string: Original='$original' -> Normalized='$normalized'" + } return $normalized } @@ -562,10 +575,11 @@ if (Test-Path -Path $driverMappingPath -PathType Leaf) { # Find all matching rules and select the most specific one $matchingRules = @() + # Normalize system model once outside the loop + $systemModelNorm = ConvertTo-ComparableModelName -Text $systemModel foreach ($rule in $driverMappings) { # Use -like for wildcard matching. - # Prepare normalized model strings (ignore special characters and collapse whitespace) - $systemModelNorm = ConvertTo-ComparableModelName -Text $systemModel + # Prepare normalized rule model string $ruleModelNorm = ConvertTo-ComparableModelName -Text $rule.Model # This checks if the system model starts with the rule model, or vice-versa, for flexibility. if ($systemManufacturer -like "$($rule.Manufacturer)*" -and ($systemModelNorm -like "$($ruleModelNorm)*" -or $ruleModelNorm -like "$systemModelNorm*")) {