Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Handle Chassis returned as slice #4629

Merged
merged 4 commits into from
Sep 9, 2024
Merged

Conversation

slntopp
Copy link
Member

@slntopp slntopp commented Sep 3, 2024

No description provided.

@@ -14,7 +14,7 @@ import (
const smbiosWindowsScript = `
$bios = Get-WmiObject -class Win32_Bios
$baseboard = Get-WmiObject Win32_BaseBoard
$chassis = Get-WmiObject Win32_SystemEnclosure
$chassis = @(Get-WmiObject Win32_SystemEnclosure)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note on PowerShell syntax:

  • The @() syntax is used to (force) create an array in PowerShell.

@slntopp
Copy link
Member Author

slntopp commented Sep 3, 2024

Can be tested with this script:

(@(Get-Process -IncludeUserName | Select-Object Name, Id, Path) | ConvertTo-Json) -eq (Get-Process -IncludeUserName | Select-Object Name, Id, Path | ConvertTo-Json)

This one tests processes, because they are always a slice, and shows that @() applied on slice returns same slice

Copy link
Contributor

github-actions bot commented Sep 3, 2024

Test Results

3 097 tests  ±0   3 096 ✅ ±0   1m 29s ⏱️ -1s
  370 suites ±0       1 💤 ±0 
   28 files   ±0       0 ❌ ±0 

Results for commit 8ba6ef8. ± Comparison against base commit 75e603d.

♻️ This comment has been updated with latest results.

@slntopp
Copy link
Member Author

slntopp commented Sep 3, 2024

Also worth noting, as documentation suggests, all Get-WmiObject calls may return multiple instances (slice)

https://powershell.one/wmi/root/cimv2/win32_systemenclosure

Model: toString(winBios.Chassis.Model),
Version: winBios.Chassis.Version,
SerialNumber: winBios.Chassis.SerialNumber,
ChassisInfo: ChassisInfo{ // TODO: Might want to make this a slice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be nil? if winBios.Chassis is 0, we may as well jst set this to nil. we're currently filling in an empty struct that holds no value. if this cannot be nil, then thats ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't technically be, since it's not a pointer
Changing the type at this point would be even more breaking than making it slice, which would've been better solution imo

@slntopp slntopp merged commit 93312b3 into main Sep 9, 2024
15 checks passed
@slntopp slntopp deleted the mik/os/win/get-chassis-fix branch September 9, 2024 09:43
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants