Skips empty driver folders during deployment

Adds validation to filter out driver folders containing only WIM files or no installable content before attempting driver injection. This prevents unnecessary processing and potential errors when scanning driver repositories.

Introduces a helper function to recursively check folders for installable driver content (non-WIM files). The validation runs before adding folders to the driver sources list, with appropriate logging when folders are skipped.

Also includes minor code formatting improvements for consistency.
This commit is contained in:
rbalsleyMSFT
2025-11-18 18:47:01 -08:00
parent 3cb4003bcd
commit 19081a2e1f
@@ -712,6 +712,38 @@ function ConvertTo-ComparableModelName {
return $normalized return $normalized
} }
function Test-DriverFolderHasInstallableContent {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
if (-not (Test-Path -Path $Path -PathType Container)) {
return $false
}
try {
$nonWimFile = Get-ChildItem -Path $Path -File -Recurse -ErrorAction Stop | Where-Object {
$extension = $_.Extension
if ([string]::IsNullOrWhiteSpace($extension)) {
return $true
}
return $extension.ToLowerInvariant() -ne '.wim'
} | Select-Object -First 1
if ($nonWimFile) {
return $true
}
return $false
}
catch {
WriteLog "Failed to inspect driver folder '$Path': $($_.Exception.Message)"
return $false
}
}
#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
@@ -1131,7 +1163,7 @@ if ($null -eq $DriverSourcePath) {
try { try {
$normalizedPath = [System.IO.Path]::GetFullPath($candidatePath) $normalizedPath = [System.IO.Path]::GetFullPath($candidatePath)
if ($normalizedPath.StartsWith($rootPath, [System.StringComparison]::OrdinalIgnoreCase)) { if ($normalizedPath.StartsWith($rootPath, [System.StringComparison]::OrdinalIgnoreCase)) {
$relativeSegment = $normalizedPath.Substring($rootPath.Length).TrimStart('\','/') $relativeSegment = $normalizedPath.Substring($rootPath.Length).TrimStart('\', '/')
if ([string]::IsNullOrWhiteSpace($relativeSegment)) { if ([string]::IsNullOrWhiteSpace($relativeSegment)) {
return Split-Path -Path $normalizedPath -Leaf return Split-Path -Path $normalizedPath -Leaf
} }
@@ -1158,6 +1190,10 @@ if ($null -eq $DriverSourcePath) {
$childModelFolders = Get-ChildItem -Path $driverFolder.FullName -Directory -ErrorAction SilentlyContinue $childModelFolders = Get-ChildItem -Path $driverFolder.FullName -Directory -ErrorAction SilentlyContinue
if (($childModelFolders.Count -gt 0) -and ($driverFolder.Parent.FullName -eq $driversRootFullPath)) { if (($childModelFolders.Count -gt 0) -and ($driverFolder.Parent.FullName -eq $driversRootFullPath)) {
foreach ($modelFolder in $childModelFolders) { foreach ($modelFolder in $childModelFolders) {
if (-not (Test-DriverFolderHasInstallableContent -Path $modelFolder.FullName)) {
WriteLog "Skipping driver folder '$($modelFolder.FullName)' because no installable files were found."
continue
}
$relativePath = & $relativePathResolver -candidatePath $modelFolder.FullName -rootPath $driversRootFullPath $relativePath = & $relativePathResolver -candidatePath $modelFolder.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{ $DriverSources += [PSCustomObject]@{
Type = 'Folder' Type = 'Folder'
@@ -1167,6 +1203,10 @@ if ($null -eq $DriverSourcePath) {
} }
} }
else { else {
if (-not (Test-DriverFolderHasInstallableContent -Path $driverFolder.FullName)) {
WriteLog "Skipping driver folder '$($driverFolder.FullName)' because no installable files were found."
continue
}
$relativePath = & $relativePathResolver -candidatePath $driverFolder.FullName -rootPath $driversRootFullPath $relativePath = & $relativePathResolver -candidatePath $driverFolder.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{ $DriverSources += [PSCustomObject]@{
Type = 'Folder' Type = 'Folder'
@@ -1199,7 +1239,7 @@ if ($null -eq $DriverSourcePath) {
Path = $DriverSources[$i].Path Path = $DriverSources[$i].Path
} }
} }
$displayArray | Format-Table -Property Number,Type,RelativePath,Path -AutoSize $displayArray | Format-Table -Property Number, Type, RelativePath, Path -AutoSize
do { do {
try { try {