From b5e8c00d92eeed9a88f4453f556239f209d8dd63 Mon Sep 17 00:00:00 2001 From: Mike Mueller Date: Thu, 18 Jun 2026 11:41:54 +0000 Subject: [PATCH] inventory: report device class (form factor) Derive a coarse device_class from SMBIOS chassis type + PCSystemType, with VM detection (manufacturer/model) and Windows Server OS taking precedence: Laptop / Desktop / Server / Tablet / Virtual Machine / Unknown. Surfaced in opsbase on the device list and Hardware tab. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/inventory.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/inventory.rs b/src/inventory.rs index d6d91a7..042021c 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -154,10 +154,42 @@ $installed_software = @($installed_software | Sort-Object name, version) $os_release = "$($os.Version)" if ($displayVersion) { $os_release = "$($os.Version) $displayVersion" } + +# Device class — a coarse form factor for asset grouping. VM first (most +# specific), then Windows Server OS, then the SMBIOS chassis type, then the +# computer-system PCSystemType as a fallback. +$enc = Get-CimInstance -ClassName Win32_SystemEnclosure -ErrorAction SilentlyContinue | Select-Object -First 1 +$chassis = @(); if ($enc) { $chassis = @($enc.ChassisTypes) } +$man = "$($cs.Manufacturer)".ToLower() +$mod = "$($cs.Model)".ToLower() +$device_class = 'Unknown' +if ($man -match 'vmware|virtualbox|innotek|qemu|xen|parallels|kvm' -or $mod -match 'virtual machine|vmware|virtualbox|kvm|qemu') { + $device_class = 'Virtual Machine' +} elseif ("$($os.Caption)" -match 'Server') { + $device_class = 'Server' +} else { + foreach ($ct in $chassis) { + if ($ct -in 8,9,10,14) { $device_class = 'Laptop'; break } + elseif ($ct -in 30,31,32) { $device_class = 'Tablet'; break } + elseif ($ct -in 17,23,28,29) { $device_class = 'Server'; break } + elseif ($ct -in 3,4,5,6,7,13,15,16,24) { $device_class = 'Desktop'; break } + } + if ($device_class -eq 'Unknown') { + switch ([int]$cs.PCSystemType) { + 1 { $device_class = 'Desktop' } + 2 { $device_class = 'Laptop' } + 3 { $device_class = 'Desktop' } + 4 { $device_class = 'Server' } + 5 { $device_class = 'Server' } + } + } +} + $result = [pscustomobject]@{ serial_number = $bios.SerialNumber manufacturer = $cs.Manufacturer model = $cs.Model + device_class = $device_class domain = $cs.Domain os_distro = $os.Caption os_release = $os_release