SSD temps via Libre Hardware monitor

273 Views Asked by At

This code brings average CPU temps via powershell script but can't find callouts to SSD or HDD temps how can i find callout documentations?

   
cls
$dll = "LibreHardwareMonitorLib.dll"

Unblock-File -LiteralPath $dll
Add-Type -LiteralPath $dll
$monitor = [LibreHardwareMonitor.Hardware.Computer]::new()
$monitor.IsCPUEnabled = $true

$monitor.Open()
[int]$temp = foreach ($sensor in $monitor.Hardware.Sensors) {
    if ($sensor.SensorType -eq 'Temperature' -and $sensor.Name -eq 'Core Average'){
        $sensor.Value
        break
    }
}
$monitor.Close()
write-host "$temp"

reason im using Libre cos its only option to make scripts via cli, if u know other hardware monitor api's that can work with powershell i would appriciate it

1

There are 1 best solutions below

0
Joan Marc Guillamon Sanz On

As seen in the LibreHardwareMonitor GitHub documentation, you are missing the Storage initiators.

Not familiar with your code but should look similar to this:

cls
$dll = "LibreHardwareMonitorLib.dll"

Unblock-File -LiteralPath $dll
Add-Type -LiteralPath $dll
$monitor = [LibreHardwareMonitor.Hardware.Computer]::new()
$monitor.IsCPUEnabled = $true
$monitor.IsStorageEnabled = $true

$monitor.Open()
[int]$temp = foreach ($sensor in $monitor.Hardware.Sensors) {
    if ($sensor.SensorType -eq 'Temperature' -and $sensor.Name -eq 'Core Average'){
        $sensor.Value
        break
    }
}
[int]$temp2 = foreach ($sensor in $monitor.Hardware.Sensors) {
    if ($sensor.SensorType -eq 'Temperature' -and $sensor.Name -eq 'Temperature'){
        $sensor.Value
        break
    }
}
$monitor.Close()
write-host "$temp"
write-host "$temp2"

Make sure to optimize the code, I have just added another loop for the SSD but just reworking the first one would be better. Also, SensorType and Name for the SSD may be different, I just used those because that is what i see in my Python app using LibreHardwareMonitor.dll.

Temperature   /nvme/0/temperature/0   45.0
Available Spare   /nvme/0/level/1   100.0
Available Spare Threshold   /nvme/0/level/2   5.0
Percentage Used   /nvme/0/level/3   0.0
Data Read   /nvme/0/data/4   1423.0
Data Written   /nvme/0/data/5   1380.0
Used Space   /nvme/0/load/0   36.56363296508789
Read Activity   /nvme/0/load/31   0.0
Write Activity   /nvme/0/load/32   1.2101701498031616
Total Activity   /nvme/0/load/33   1.3301831483840942
Read Rate   /nvme/0/throughput/34   0.0
Write Rate   /nvme/0/throughput/35   109381.328125