mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
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.
This commit is contained in:
@@ -202,76 +202,72 @@ function Get-SystemInformation {
|
|||||||
|
|
||||||
$normalizedManufacturer = Get-NormalizedManufacturer -Manufacturer $systemManufacturer
|
$normalizedManufacturer = Get-NormalizedManufacturer -Manufacturer $systemManufacturer
|
||||||
$msSystemInformation = Get-CimInstance -Namespace 'root\WMI' -Class MS_SystemInformation -ErrorAction SilentlyContinue
|
$msSystemInformation = Get-CimInstance -Namespace 'root\WMI' -Class MS_SystemInformation -ErrorAction SilentlyContinue
|
||||||
$systemSkuValue = $null
|
# Capture manufacturer-specific identifiers once so downstream logic stays simple.
|
||||||
$fallbackSkuValue = $null
|
$manufacturerMetadata = [pscustomobject]@{
|
||||||
$machineTypeValue = $null
|
Label = 'System ID'
|
||||||
$deviceIdentifierLabel = 'System ID'
|
SystemSku = $null
|
||||||
$deviceIdentifierValue = $null
|
FallbackSku = $null
|
||||||
|
MachineType = $null
|
||||||
|
IdentifierValue = $null
|
||||||
|
}
|
||||||
|
|
||||||
switch ($normalizedManufacturer) {
|
switch ($normalizedManufacturer) {
|
||||||
'Dell' {
|
'Dell' {
|
||||||
if ($msSystemInformation -and $msSystemInformation.SystemSku) {
|
if ($msSystemInformation -and $msSystemInformation.SystemSku) {
|
||||||
$systemSkuValue = $msSystemInformation.SystemSku.Trim()
|
$manufacturerMetadata.SystemSku = $msSystemInformation.SystemSku.Trim()
|
||||||
}
|
}
|
||||||
$oemStringArray = $computerSystem | Select-Object -ExpandProperty OEMStringArray -ErrorAction SilentlyContinue
|
$oemStringArray = $computerSystem | Select-Object -ExpandProperty OEMStringArray -ErrorAction SilentlyContinue
|
||||||
if ($oemStringArray) {
|
if ($oemStringArray) {
|
||||||
$joinedOemString = ($oemStringArray -join ' ')
|
$joinedOemString = ($oemStringArray -join ' ')
|
||||||
$fallbackMatches = [regex]::Matches($joinedOemString, '\[\S*]')
|
$fallbackMatches = [regex]::Matches($joinedOemString, '\[\S*]')
|
||||||
if ($fallbackMatches.Count -gt 0) {
|
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
|
break
|
||||||
}
|
}
|
||||||
'HP' {
|
'HP' {
|
||||||
if ($msSystemInformation -and $msSystemInformation.BaseBoardProduct) {
|
if ($msSystemInformation -and $msSystemInformation.BaseBoardProduct) {
|
||||||
$systemSkuValue = $msSystemInformation.BaseBoardProduct.Trim()
|
$manufacturerMetadata.SystemSku = $msSystemInformation.BaseBoardProduct.Trim()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
'Lenovo' {
|
'Lenovo' {
|
||||||
$modelValue = $computerSystem.Model
|
$modelValue = $computerSystem.Model
|
||||||
if (-not [string]::IsNullOrWhiteSpace($modelValue) -and $modelValue.Length -ge 4) {
|
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
|
break
|
||||||
}
|
}
|
||||||
default {
|
default {
|
||||||
if ($msSystemInformation -and $msSystemInformation.SystemSku) {
|
if ($msSystemInformation -and $msSystemInformation.SystemSku) {
|
||||||
$systemSkuValue = $msSystemInformation.SystemSku.Trim()
|
$manufacturerMetadata.SystemSku = $msSystemInformation.SystemSku.Trim()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$normalizedSystemSku = if ($systemSkuValue) { $systemSkuValue.Trim().ToUpperInvariant() } else { $null }
|
# Normalize identifiers once for UI display and driver mapping.
|
||||||
$normalizedFallbackSku = if ($fallbackSkuValue) { $fallbackSkuValue.Trim().ToUpperInvariant() } else { $null }
|
$normalizedSystemSku = if ($manufacturerMetadata.SystemSku) { $manufacturerMetadata.SystemSku.Trim().ToUpperInvariant() } else { $null }
|
||||||
$normalizedMachineType = if ($machineTypeValue) { $machineTypeValue.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) {
|
if ($null -eq $manufacturerMetadata.IdentifierValue) {
|
||||||
'Lenovo' {
|
if ($normalizedManufacturer -eq 'Lenovo' -and $normalizedMachineType) {
|
||||||
$deviceIdentifierLabel = 'Machine Type'
|
$manufacturerMetadata.IdentifierValue = $normalizedMachineType
|
||||||
if ($normalizedMachineType) {
|
|
||||||
$deviceIdentifierValue = $normalizedMachineType
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
'Dell' {
|
elseif ($normalizedSystemSku) {
|
||||||
if ($normalizedFallbackSku) {
|
$manufacturerMetadata.IdentifierValue = $normalizedSystemSku
|
||||||
$deviceIdentifierValue = $normalizedFallbackSku
|
|
||||||
}
|
|
||||||
elseif ($normalizedSystemSku) {
|
|
||||||
$deviceIdentifierValue = $normalizedSystemSku
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'HP' {
|
|
||||||
if ($normalizedSystemSku) {
|
|
||||||
$deviceIdentifierValue = $normalizedSystemSku
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default {
|
|
||||||
if ($normalizedSystemSku) {
|
|
||||||
$deviceIdentifierValue = $normalizedSystemSku
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +313,7 @@ function Get-SystemInformation {
|
|||||||
"FallbackSkuNormalized" = $normalizedFallbackSku
|
"FallbackSkuNormalized" = $normalizedFallbackSku
|
||||||
"MachineTypeNormalized" = $normalizedMachineType
|
"MachineTypeNormalized" = $normalizedMachineType
|
||||||
}
|
}
|
||||||
$sysInfoData[$deviceIdentifierLabel] = if ($deviceIdentifierValue) { $deviceIdentifierValue } else { 'Not Detected' }
|
$sysInfoData[$manufacturerMetadata.Label] = if ($manufacturerMetadata.IdentifierValue) { $manufacturerMetadata.IdentifierValue } else { 'Not Detected' }
|
||||||
|
|
||||||
return [PSCustomObject]$sysInfoData
|
return [PSCustomObject]$sysInfoData
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user