Add robust sanitization for names used in paths

Introduces a new common function, `ConvertTo-SafeName`, to sanitize strings by removing characters that are invalid in Windows file paths.

This function is now used consistently when creating directory and file names for drivers (Dell, HP, Lenovo, Microsoft) and applications to prevent path-related errors. It replaces several ad-hoc sanitization methods with a single, more robust implementation.
This commit is contained in:
rbalsleyMSFT
2025-09-16 16:43:43 -07:00
parent 8d7e4d1066
commit cb14e84a26
7 changed files with 40 additions and 12 deletions
+3 -1
View File
@@ -904,8 +904,10 @@ function Get-MicrosoftDrivers {
New-Item -Path $DriversFolder -ItemType Directory -Force | Out-Null
WriteLog "Drivers folder created"
}
$sanitizedModel = ConvertTo-SafeName -Name $Model
if ($sanitizedModel -ne $Model) { WriteLog "Sanitized model name: '$Model' -> '$sanitizedModel'" }
$surfaceDriversPath = Join-Path -Path $DriversFolder -ChildPath $Make
$modelPath = Join-Path -Path $surfaceDriversPath -ChildPath $Model
$modelPath = Join-Path -Path $surfaceDriversPath -ChildPath $sanitizedModel
if (-Not (Test-Path -Path $modelPath)) {
WriteLog "Creating model folder: $modelPath"
New-Item -Path $modelPath -ItemType Directory | Out-Null