PowerShell/Scripts/check-cpu-temp.ps1

43 lines
1.1 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2021-09-24 17:19:49 +02:00
Checks the CPU temperature
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2021-10-12 21:51:51 +02:00
This script checks the CPU temperature.
2021-07-13 21:10:02 +02:00
.EXAMPLE
2021-09-24 17:19:49 +02:00
PS> ./check-cpu-temp
2021-10-17 12:16:06 +02:00
CPU has 30.3 °C: good
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2021-08-29 17:50:03 +02:00
Author: Markus Fleschutz · License: CC0
2021-03-20 16:13:54 +01:00
#>
try {
2021-06-07 08:48:17 +02:00
if (test-path "/sys/class/thermal/thermal_zone0/temp" -pathType leaf) {
2021-03-29 17:09:59 +02:00
[int]$IntTemp = get-content "/sys/class/thermal/thermal_zone0/temp"
$Temp = [math]::round($IntTemp / 1000.0, 1)
2021-03-20 16:13:54 +01:00
} else {
2021-05-20 11:54:35 +02:00
$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
$Temp = @($data)[0].HighPrecisionTemperature
2021-05-20 11:55:22 +02:00
$Temp = [math]::round($Temp / 100.0, 1)
2021-03-20 16:13:54 +01:00
}
2021-10-17 12:13:20 +02:00
if ($Temp -gt 80) {
2021-10-17 12:16:06 +02:00
"⚠️ CPU has $Temp °C: too high!"
2021-03-29 16:21:03 +02:00
exit 1
2021-10-17 12:13:20 +02:00
} elseif ($Temp -gt 50) {
2021-10-17 12:16:06 +02:00
"✔️ CPU has $Temp °C: quite high"
2021-10-17 12:13:20 +02:00
} elseif ($Temp -gt 0) {
2021-10-17 12:16:06 +02:00
"✔️ CPU has $Temp °C: good"
2021-10-17 12:13:20 +02:00
} elseif ($Temp -gt -20) {
2021-10-17 12:16:06 +02:00
"✔️ CPU has $Temp °C: quite low"
2021-03-20 16:23:49 +01:00
} else {
2021-10-17 12:16:06 +02:00
"⚠️ CPU has $Temp °C: too low!"
2021-10-17 12:13:20 +02:00
exit 1
2021-03-20 16:23:49 +01:00
}
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-03-20 16:13:54 +01:00
} catch {
2021-09-16 20:19:10 +02:00
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
2021-03-20 16:13:54 +01:00
exit 1
}