Featured image of post Monitoring with PowerShell: Monitoring system temperatures

Monitoring with PowerShell: Monitoring system temperatures

This blog was requested by one of the partners I work with. At times, you want to monitor the device temperatures and fan settings; you don’t want a machine to be constantly making noise because it’s having a hard time cooling down. While I’m not really one of the engineers that firmly believes in a high impact of temperature on normal workstations I can understand the annoyance the extra noise brings.

To monitor this, we’re using WMI/CIM. Unfortunately, not all manufacturers publish this information to WMI. If the script fails with “Could not get CPU temperature. Your manufacturer might not support this.” Then this is the case. You’ll be able to use external tools to get the temperature then.

1
2
3
4
5
6
7
8
9
try {
    $t = Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" -ErrorAction Stop | Where-Object -Property instancename -EQ "ACPI\ThermalZone\TZ01_0" | Select-object -first 1
    $currentTempKelvin = $t.CurrentTemperature / 10
    $currentTempCelsius = $currentTempKelvin - 273.15
    $currentTempCelsius.ToString() + "°C"
}
Catch {
    Write-Host "Could not get CPU temperature. Your manafacturer might not support this."
}

And that’s it! as always, Happy PowerShelling!

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy