2021-09-27 10:38:12 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2022-01-29 12:47:46 +01:00
|
|
|
|
Checks the CPU temperature
|
2021-10-04 21:29:23 +02:00
|
|
|
|
.DESCRIPTION
|
2022-05-31 14:38:34 +02:00
|
|
|
|
This PowerShell script queries the CPU temperature and returns it.
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2021-12-01 10:23:15 +01:00
|
|
|
|
PS> ./check-cpu
|
2022-05-31 14:39:11 +02:00
|
|
|
|
CPU is 30.3°C warm.
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2022-05-31 14:38:34 +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-12-08 17:08:01 +01:00
|
|
|
|
$Reply = "CPU is $($Temp)°C extremely hot!"
|
2021-10-17 12:13:20 +02:00
|
|
|
|
} elseif ($Temp -gt 50) {
|
2021-12-08 17:08:01 +01:00
|
|
|
|
$Reply = "CPU is $($Temp)°C hot."
|
2021-10-17 12:13:20 +02:00
|
|
|
|
} elseif ($Temp -gt 0) {
|
2021-12-08 17:08:01 +01:00
|
|
|
|
$Reply = "CPU is $($Temp)°C warm."
|
2021-10-17 12:13:20 +02:00
|
|
|
|
} elseif ($Temp -gt -20) {
|
2021-12-08 17:08:01 +01:00
|
|
|
|
$Reply = "CPU is $($Temp)°C cold."
|
2021-03-20 16:23:49 +01:00
|
|
|
|
} else {
|
2021-12-08 17:08:01 +01:00
|
|
|
|
$Reply = "CPU is $($Temp)°C extremely cold!"
|
2021-03-20 16:23:49 +01:00
|
|
|
|
}
|
2022-05-31 14:38:34 +02:00
|
|
|
|
& "$PSScriptRoot/give-reply.ps1" $Reply
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-03-20 16:13:54 +01:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-03-20 16:13:54 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|