Ajout d'un README.md avec le descriptif et les instructions L'ancien README.md s'appelle désormais CHANGELOG.md Activation du pavé numérique par défaut pour les installations sans assistance Nouveau design pour la fenêtre de déploiement. Ajout de paramètre pour pouvoir procéder à une installation totalement automatisée Ajout de paramètre pour copier au choix sources, drivers ou les deux sur C:\DeployVenter avant leur usage par DISM.
77 lines
4.4 KiB
PowerShell
77 lines
4.4 KiB
PowerShell
# DeployCenter - offline driver pack detection.
|
|
|
|
function ConvertTo-DeployCenterDriverKey {
|
|
param([AllowNull()][string]$Value)
|
|
if ([string]::IsNullOrWhiteSpace($Value)) { return '' }
|
|
return ([regex]::Replace($Value, '[^A-Za-z0-9]', '')).ToUpperInvariant()
|
|
}
|
|
|
|
function Get-DeployCenterDriverManufacturerFolder {
|
|
param([AllowNull()][string]$Manufacturer)
|
|
if ($Manufacturer -match '(?i)lenovo') { return 'Lenovo' }
|
|
if ($Manufacturer -match '(?i)dell') { return 'Dell' }
|
|
if ($Manufacturer -match '(?i)hewlett|\bHP\b') { return 'HP' }
|
|
if ($Manufacturer -match '(?i)microsoft') { return 'Microsoft' }
|
|
return $null
|
|
}
|
|
|
|
function Get-DeployCenterDriverWindowsFolder {
|
|
param([AllowNull()][string]$EditionName)
|
|
if ([string]::IsNullOrWhiteSpace($EditionName)) { return $null }
|
|
if ($EditionName -match '(?i)Windows\s+Server\s+(\d{4})') { return "Windows Server $($matches[1])" }
|
|
if ($EditionName -match '(?i)Windows\s+11') { return 'Windows 11' }
|
|
if ($EditionName -match '(?i)Windows\s+10') { return 'Windows 10' }
|
|
return $null
|
|
}
|
|
|
|
function Find-DeployCenterDriverPack {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory=$true)][string]$DriverRoot,
|
|
[AllowNull()][string]$Manufacturer,
|
|
[AllowNull()][string]$Model,
|
|
[AllowNull()][string]$SystemSKU,
|
|
[AllowNull()][string]$EditionName
|
|
)
|
|
|
|
$vendor = Get-DeployCenterDriverManufacturerFolder -Manufacturer $Manufacturer
|
|
$osFolder = Get-DeployCenterDriverWindowsFolder -EditionName $EditionName
|
|
$vendorRoot = if ($vendor) { Join-Path $DriverRoot $vendor } else { Join-Path $DriverRoot '_unknown_vendor' }
|
|
$modelFolder = $null
|
|
if (Test-Path -LiteralPath $vendorRoot -PathType Container) {
|
|
$prefixes = @()
|
|
$modelKey = ConvertTo-DeployCenterDriverKey $Model
|
|
$skuKey = ConvertTo-DeployCenterDriverKey $SystemSKU
|
|
if ($modelKey) { $prefixes += $modelKey }
|
|
if ($skuKey) { $prefixes += $skuKey }
|
|
$candidates = @()
|
|
foreach ($directory in @(Get-ChildItem -LiteralPath $vendorRoot -Directory -ErrorAction SilentlyContinue)) {
|
|
$key = ConvertTo-DeployCenterDriverKey $directory.Name
|
|
if (-not $key) { continue }
|
|
foreach ($prefix in $prefixes) {
|
|
if ($prefix.StartsWith($key, [StringComparison]::OrdinalIgnoreCase)) {
|
|
$candidates += [pscustomobject]@{ Path = $directory.FullName; KeyLength = $key.Length }
|
|
break
|
|
}
|
|
}
|
|
}
|
|
$longest = ($candidates | Measure-Object -Property KeyLength -Maximum).Maximum
|
|
$best = @($candidates | Where-Object { $_.KeyLength -eq $longest })
|
|
if ($best.Count -eq 1) { $modelFolder = $best[0].Path }
|
|
elseif ($best.Count -gt 1) {
|
|
return [pscustomobject]@{ Found=$false; Status='Ambiguous model match'; DriverPath=$null; SearchPath=$vendorRoot; InfCount=0 }
|
|
}
|
|
}
|
|
$searchPath = if ($modelFolder -and $osFolder) { Join-Path $modelFolder $osFolder } elseif ($vendor -and $osFolder) { Join-Path $vendorRoot ('<model>\' + $osFolder) } elseif ($vendor) { Join-Path $vendorRoot '<Windows version>' } else { Join-Path $DriverRoot '<vendor>\<model>\<Windows version>' }
|
|
if (-not $vendor) { return [pscustomobject]@{ Found=$false; Status='Unsupported manufacturer'; DriverPath=$null; SearchPath=$searchPath; InfCount=0 } }
|
|
if (-not $osFolder) { return [pscustomobject]@{ Found=$false; Status='Unrecognized Windows version'; DriverPath=$null; SearchPath=$searchPath; InfCount=0 } }
|
|
if (-not $modelFolder) { return [pscustomobject]@{ Found=$false; Status='Model not found'; DriverPath=$null; SearchPath=$searchPath; InfCount=0 } }
|
|
$searchPath = Join-Path $modelFolder $osFolder
|
|
if (-not (Test-Path -LiteralPath $searchPath -PathType Container)) { return [pscustomobject]@{ Found=$false; Status='Version folder not found'; DriverPath=$null; SearchPath=$searchPath; InfCount=0 } }
|
|
$infCount = @(Get-ChildItem -LiteralPath $searchPath -Filter '*.inf' -File -Recurse -ErrorAction SilentlyContinue).Count
|
|
if ($infCount -eq 0) { return [pscustomobject]@{ Found=$false; Status='No INF files'; DriverPath=$null; SearchPath=$searchPath; InfCount=0 } }
|
|
return [pscustomobject]@{ Found=$true; Status='Driver pack found'; DriverPath=$searchPath; SearchPath=$searchPath; InfCount=$infCount }
|
|
}
|
|
|
|
Export-ModuleMember -Function Find-DeployCenterDriverPack
|