From 3deb8fb8d2cc4f1ff6adf49e932c97617152d847 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Mon, 17 Nov 2025 12:59:54 -0800 Subject: [PATCH] Refactors manufacturer metadata handling Consolidates manufacturer-specific identifier logic into a single metadata object to reduce code duplication and improve maintainability. Previously, manufacturer identifiers were captured and assigned using separate variables with duplicated switch-case logic. Now captures all metadata (SystemSku, FallbackSku, MachineType, Label, IdentifierValue) upfront in a structured object, allowing downstream logic to reference a single source of truth. Improves readability by centralizing the identifier selection logic within each manufacturer case rather than scattering it across multiple switch statements. --- .../WinPEDeployFFUFiles/ApplyFFU.ps1 | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 index 1be0323..17f3b16 100644 --- a/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 +++ b/FFUDevelopment/WinPEDeployFFUFiles/ApplyFFU.ps1 @@ -202,76 +202,72 @@ function Get-SystemInformation { $normalizedManufacturer = Get-NormalizedManufacturer -Manufacturer $systemManufacturer $msSystemInformation = Get-CimInstance -Namespace 'root\WMI' -Class MS_SystemInformation -ErrorAction SilentlyContinue - $systemSkuValue = $null - $fallbackSkuValue = $null - $machineTypeValue = $null - $deviceIdentifierLabel = 'System ID' - $deviceIdentifierValue = $null + # Capture manufacturer-specific identifiers once so downstream logic stays simple. + $manufacturerMetadata = [pscustomobject]@{ + Label = 'System ID' + SystemSku = $null + FallbackSku = $null + MachineType = $null + IdentifierValue = $null + } switch ($normalizedManufacturer) { 'Dell' { if ($msSystemInformation -and $msSystemInformation.SystemSku) { - $systemSkuValue = $msSystemInformation.SystemSku.Trim() + $manufacturerMetadata.SystemSku = $msSystemInformation.SystemSku.Trim() } $oemStringArray = $computerSystem | Select-Object -ExpandProperty OEMStringArray -ErrorAction SilentlyContinue if ($oemStringArray) { $joinedOemString = ($oemStringArray -join ' ') $fallbackMatches = [regex]::Matches($joinedOemString, '\[\S*]') if ($fallbackMatches.Count -gt 0) { - $fallbackSkuValue = $fallbackMatches[0].Value.TrimStart('[').TrimEnd(']') + $manufacturerMetadata.FallbackSku = $fallbackMatches[0].Value.TrimStart('[').TrimEnd(']') } } + if ($manufacturerMetadata.FallbackSku) { + $manufacturerMetadata.IdentifierValue = $manufacturerMetadata.FallbackSku + } + elseif ($manufacturerMetadata.SystemSku) { + $manufacturerMetadata.IdentifierValue = $manufacturerMetadata.SystemSku + } break } 'HP' { if ($msSystemInformation -and $msSystemInformation.BaseBoardProduct) { - $systemSkuValue = $msSystemInformation.BaseBoardProduct.Trim() + $manufacturerMetadata.SystemSku = $msSystemInformation.BaseBoardProduct.Trim() } break } 'Lenovo' { $modelValue = $computerSystem.Model if (-not [string]::IsNullOrWhiteSpace($modelValue) -and $modelValue.Length -ge 4) { - $machineTypeValue = $modelValue.Substring(0, 4).Trim() + $manufacturerMetadata.MachineType = $modelValue.Substring(0, 4).Trim() + } + $manufacturerMetadata.Label = 'Machine Type' + if ($manufacturerMetadata.MachineType) { + $manufacturerMetadata.IdentifierValue = $manufacturerMetadata.MachineType } break } default { if ($msSystemInformation -and $msSystemInformation.SystemSku) { - $systemSkuValue = $msSystemInformation.SystemSku.Trim() + $manufacturerMetadata.SystemSku = $msSystemInformation.SystemSku.Trim() } break } } - $normalizedSystemSku = if ($systemSkuValue) { $systemSkuValue.Trim().ToUpperInvariant() } else { $null } - $normalizedFallbackSku = if ($fallbackSkuValue) { $fallbackSkuValue.Trim().ToUpperInvariant() } else { $null } - $normalizedMachineType = if ($machineTypeValue) { $machineTypeValue.Trim().ToUpperInvariant() } else { $null } + # Normalize identifiers once for UI display and driver mapping. + $normalizedSystemSku = if ($manufacturerMetadata.SystemSku) { $manufacturerMetadata.SystemSku.Trim().ToUpperInvariant() } else { $null } + $normalizedFallbackSku = if ($manufacturerMetadata.FallbackSku) { $manufacturerMetadata.FallbackSku.Trim().ToUpperInvariant() } else { $null } + $normalizedMachineType = if ($manufacturerMetadata.MachineType) { $manufacturerMetadata.MachineType.Trim().ToUpperInvariant() } else { $null } - switch ($normalizedManufacturer) { - 'Lenovo' { - $deviceIdentifierLabel = 'Machine Type' - if ($normalizedMachineType) { - $deviceIdentifierValue = $normalizedMachineType - } + if ($null -eq $manufacturerMetadata.IdentifierValue) { + if ($normalizedManufacturer -eq 'Lenovo' -and $normalizedMachineType) { + $manufacturerMetadata.IdentifierValue = $normalizedMachineType } - 'Dell' { - if ($normalizedFallbackSku) { - $deviceIdentifierValue = $normalizedFallbackSku - } - elseif ($normalizedSystemSku) { - $deviceIdentifierValue = $normalizedSystemSku - } - } - 'HP' { - if ($normalizedSystemSku) { - $deviceIdentifierValue = $normalizedSystemSku - } - } - default { - if ($normalizedSystemSku) { - $deviceIdentifierValue = $normalizedSystemSku - } + elseif ($normalizedSystemSku) { + $manufacturerMetadata.IdentifierValue = $normalizedSystemSku } } @@ -317,7 +313,7 @@ function Get-SystemInformation { "FallbackSkuNormalized" = $normalizedFallbackSku "MachineTypeNormalized" = $normalizedMachineType } - $sysInfoData[$deviceIdentifierLabel] = if ($deviceIdentifierValue) { $deviceIdentifierValue } else { 'Not Detected' } + $sysInfoData[$manufacturerMetadata.Label] = if ($manufacturerMetadata.IdentifierValue) { $manufacturerMetadata.IdentifierValue } else { 'Not Detected' } return [PSCustomObject]$sysInfoData }