fix: - Improved handling of special characters with driver model names when doing automatic driver/model matching when applying the FFU to a device.

- Added some console output when drivers are being installed from a folder
This commit is contained in:
rbalsleyMSFT
2025-08-13 18:48:28 -07:00
parent 0423ac31d9
commit 85383f989a
@@ -203,6 +203,19 @@ function Stop-Script {
Read-Host "Press Enter to exit" Read-Host "Press Enter to exit"
Exit Exit
} }
function ConvertTo-ComparableModelName {
[CmdletBinding()]
param(
[string]$Text
)
# Normalize model strings by converting any non-alphanumeric sequence to a single space, collapsing whitespace, and trimming.
if ($null -eq $Text) { return '' }
$normalized = ($Text -replace '[^A-Za-z0-9]+', ' ')
$normalized = ($normalized -replace '\s+', ' ').Trim()
return $normalized
}
#Get USB Drive and create log file #Get USB Drive and create log file
$LogFileName = 'ScriptLog.txt' $LogFileName = 'ScriptLog.txt'
$USBDrive = Get-USBDrive $USBDrive = Get-USBDrive
@@ -551,9 +564,12 @@ if (Test-Path -Path $driverMappingPath -PathType Leaf) {
$matchingRules = @() $matchingRules = @()
foreach ($rule in $driverMappings) { foreach ($rule in $driverMappings) {
# Use -like for wildcard matching. # Use -like for wildcard matching.
# Prepare normalized model strings (ignore special characters and collapse whitespace)
$systemModelNorm = ConvertTo-ComparableModelName -Text $systemModel
$ruleModelNorm = ConvertTo-ComparableModelName -Text $rule.Model
# This checks if the system model starts with the rule model, or vice-versa, for flexibility. # This checks if the system model starts with the rule model, or vice-versa, for flexibility.
if ($systemManufacturer -like "$($rule.Manufacturer)*" -and ($systemModel -like "$($rule.Model)*" -or $rule.Model -like "$systemModel*")) { if ($systemManufacturer -like "$($rule.Manufacturer)*" -and ($systemModelNorm -like "$($ruleModelNorm)*" -or $ruleModelNorm -like "$systemModelNorm*")) {
WriteLog "Match found: Manufacturer='$($rule.Manufacturer)', Model='$($rule.Model)'" WriteLog "Match found: Manufacturer='$($rule.Manufacturer)', Model='$($rule.Model)' (Normalized: System='$systemModelNorm', Rule='$ruleModelNorm')"
$matchingRules += $rule $matchingRules += $rule
} }
} }
@@ -846,7 +862,7 @@ If ($computername) {
} }
} }
#Add Drivers # Add Drivers
if ($null -ne $DriverSourcePath) { if ($null -ne $DriverSourcePath) {
Write-SectionHeader -Title 'Installing Drivers' Write-SectionHeader -Title 'Installing Drivers'
if ($DriverSourceType -eq 'WIM') { if ($DriverSourceType -eq 'WIM') {
@@ -894,8 +910,11 @@ if ($null -ne $DriverSourcePath) {
} }
elseif ($DriverSourceType -eq 'Folder') { elseif ($DriverSourceType -eq 'Folder') {
WriteLog "Injecting drivers from folder: $DriverSourcePath" WriteLog "Injecting drivers from folder: $DriverSourcePath"
Write-Host "Injecting drivers from folder: $DriverSourcePath"
Write-Host "This may take a while, please be patient."
Invoke-Process dism.exe "/image:W:\ /Add-Driver /Driver:""$DriverSourcePath"" /Recurse" Invoke-Process dism.exe "/image:W:\ /Add-Driver /Driver:""$DriverSourcePath"" /Recurse"
WriteLog "Driver injection from folder succeeded." WriteLog "Driver injection from folder succeeded."
Write-Host "Driver injection from folder succeeded."
} }
} }
else { else {