mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-29 11:24:27 +01:00
Update check-cpu.ps1
This commit is contained in:
parent
bffb7d6a11
commit
e0b603f1b6
@ -12,27 +12,38 @@
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function GetCPUTemperatureInCelsius {
|
||||
$Temp = 99999.9 # unsupported
|
||||
if ($IsLinux) {
|
||||
if (Test-Path "/sys/class/thermal/thermal_zone0/temp" -pathType leaf) {
|
||||
[int]$IntTemp = Get-Content "/sys/class/thermal/thermal_zone0/temp"
|
||||
$Temp = [math]::round($IntTemp / 1000.0, 1)
|
||||
}
|
||||
} else {
|
||||
$Objects = Get-WmiObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
|
||||
foreach ($Obj in $Objects) {
|
||||
$HiPrec = $Obj.HighPrecisionTemperature
|
||||
$Temp = [math]::round($HiPrec / 100.0, 1)
|
||||
}
|
||||
}
|
||||
return $Temp;
|
||||
}
|
||||
|
||||
try {
|
||||
if (test-path "/sys/class/thermal/thermal_zone0/temp" -pathType leaf) {
|
||||
[int]$IntTemp = get-content "/sys/class/thermal/thermal_zone0/temp"
|
||||
$Temp = [math]::round($IntTemp / 1000.0, 1)
|
||||
} else {
|
||||
$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
|
||||
$Temp = @($data)[0].HighPrecisionTemperature
|
||||
$Temp = [math]::round($Temp / 100.0, 1)
|
||||
}
|
||||
if ($Temp -gt 80) {
|
||||
$Reply = "⚠️ CPU is too hot at $($Temp)°C!"
|
||||
$Temp = GetCPUTemperatureInCelsius
|
||||
if ($Temp -eq 99999.9) {
|
||||
"⚠️ CPU temperature query is unsupported."
|
||||
} elseif ($Temp -gt 80) {
|
||||
"⚠️ CPU is too hot at $($Temp)°C!"
|
||||
} elseif ($Temp -gt 50) {
|
||||
$Reply = "✅ CPU is $($Temp)°C hot."
|
||||
"✅ CPU is $($Temp)°C hot."
|
||||
} elseif ($Temp -gt 0) {
|
||||
$Reply = "✅ CPU is $($Temp)°C warm."
|
||||
"✅ CPU is $($Temp)°C warm."
|
||||
} elseif ($Temp -gt -20) {
|
||||
$Reply = "✅ CPU is $($Temp)°C cold."
|
||||
"✅ CPU is $($Temp)°C cold."
|
||||
} else {
|
||||
$Reply = "⚠️ CPU is too cold at $($Temp)°C!"
|
||||
"⚠️ CPU is too cold at $($Temp)°C!"
|
||||
}
|
||||
"$Reply"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user