2021-09-27 10:38:12 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2021-12-01 10:23:15 +01:00
|
|
|
|
Checks the CPU
|
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-12-01 10:23:15 +01:00
|
|
|
|
PS> ./check-cpu
|
|
|
|
|
✔️ CPU has 30.3 °C
|
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-12-02 15:25:42 +01:00
|
|
|
|
$Reply = "$($Temp)°C CPU temperature, that's too high!"
|
2021-10-17 12:13:20 +02:00
|
|
|
|
} elseif ($Temp -gt 50) {
|
2021-12-02 15:25:42 +01:00
|
|
|
|
$Reply = "$($Temp)°C CPU temperature, that's quite high"
|
2021-10-17 12:13:20 +02:00
|
|
|
|
} elseif ($Temp -gt 0) {
|
2021-12-02 15:26:52 +01:00
|
|
|
|
$Reply = "$($Temp)°C CPU temperature"
|
2021-10-17 12:13:20 +02:00
|
|
|
|
} elseif ($Temp -gt -20) {
|
2021-12-02 15:26:52 +01:00
|
|
|
|
$Reply = "$($Temp)°C CPU temperature, that's quite low"
|
2021-03-20 16:23:49 +01:00
|
|
|
|
} else {
|
2021-12-02 15:26:52 +01:00
|
|
|
|
$Reply = "$($Temp)°C CPU temperature, that's too low!"
|
2021-03-20 16:23:49 +01:00
|
|
|
|
}
|
2021-12-01 10:25:03 +01:00
|
|
|
|
"✔️ $Reply"
|
2021-12-01 10:23:15 +01:00
|
|
|
|
& "$PSScriptRoot/speak-english.ps1" "$Reply"
|
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
|
|
|
|
|
}
|