2021-04-21 19:53:52 +02:00
|
|
|
|
<#
|
2021-04-07 15:17:49 +02:00
|
|
|
|
.SYNTAX check-cpu-temp.ps1
|
2021-03-22 20:10:18 +01:00
|
|
|
|
.DESCRIPTION checks the CPU temperature
|
|
|
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES 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-03-20 16:23:49 +01:00
|
|
|
|
if ($Temp -gt "80") {
|
2021-05-26 14:07:54 +02:00
|
|
|
|
write-error "⚠️ $Temp °C CPU temperature is too high!"
|
2021-03-29 16:21:03 +02:00
|
|
|
|
exit 1
|
|
|
|
|
} elseif ($Temp -lt "-20") {
|
2021-05-26 14:07:54 +02:00
|
|
|
|
write-error "⚠️ $Temp °C CPU temperature is too low!"
|
2021-03-29 16:21:03 +02:00
|
|
|
|
exit 1
|
|
|
|
|
} elseif ($Temp -gt "50") {
|
2021-05-26 14:07:54 +02:00
|
|
|
|
"✔️ $Temp °C CPU temperature - quite high"
|
2021-03-29 16:21:03 +02:00
|
|
|
|
} elseif ($Temp -lt "0") {
|
2021-05-26 14:07:54 +02:00
|
|
|
|
"✔️ $Temp °C CPU temperature - quite low"
|
2021-03-20 16:23:49 +01:00
|
|
|
|
} else {
|
2021-05-26 14:07:54 +02:00
|
|
|
|
"✔️ $Temp °C CPU temperature - good"
|
2021-03-20 16:23:49 +01:00
|
|
|
|
}
|
2021-03-20 16:13:54 +01:00
|
|
|
|
exit 0
|
|
|
|
|
} catch {
|
2021-05-02 21:30:48 +02:00
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-03-20 16:13:54 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|