Update check-cpu.ps1

This commit is contained in:
Markus Fleschutz 2023-11-23 13:41:50 +01:00
parent 398d10fc29
commit 21db8c52bd

View File

@ -12,7 +12,19 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
function GetProcessorTemperature { function GetCPUArchitecture {
if ("$env:PROCESSOR_ARCHITECTURE" -ne "") { return "$env:PROCESSOR_ARCHITECTURE" }
if ($IsLinux) {
$Name = $PSVersionTable.OS
if ($Name -like "*-generic *") {
if ([System.Environment]::Is64BitOperatingSystem) { return "x64" } else { return "x86" }
} elseif ($Name -like "*-raspi *") {
if ([System.Environment]::Is64BitOperatingSystem) { return "ARM64" } else { return "ARM32" }
} elseif ([System.Environment]::Is64BitOperatingSystem) { return "64-bit" } else { return "32-bit" }
}
}
function GetCPUTemperature {
$temp = 99999.9 # unsupported $temp = 99999.9 # unsupported
if ($IsLinux) { if ($IsLinux) {
if (Test-Path "/sys/class/thermal/thermal_zone0/temp" -pathType leaf) { if (Test-Path "/sys/class/thermal/thermal_zone0/temp" -pathType leaf) {
@ -29,37 +41,10 @@ function GetProcessorTemperature {
return $temp return $temp
} }
function GetProcessorArchitecture {
if ("$env:PROCESSOR_ARCHITECTURE" -ne "") { return "$env:PROCESSOR_ARCHITECTURE" }
if ($IsLinux) {
$Name = $PSVersionTable.OS
if ($Name -like "*-generic *") {
if ([System.Environment]::Is64BitOperatingSystem) { return "x64" } else { return "x86" }
} elseif ($Name -like "*-raspi *") {
if ([System.Environment]::Is64BitOperatingSystem) { return "ARM64" } else { return "ARM32" }
} else {
return ""
}
}
}
try { try {
Write-Progress "Querying CPU status... " Write-Progress "Querying CPU status... "
$status = "" $status = ""
$celsius = GetProcessorTemperature $arch = GetCPUArchitecture
if ($celsius -eq 99999.9) {
$temp = "no temp"
} elseif ($celsius -gt 50) {
$temp = "$($celsius)°C"
$status = "⚠️"
} elseif ($celsius -lt 0) {
$temp = "$($celsius)°C"
$status = "⚠️"
} else {
$temp = "$($celsius)°C"
}
$arch = GetProcessorArchitecture
if ($IsLinux) { if ($IsLinux) {
$cpuName = "$arch CPU" $cpuName = "$arch CPU"
$arch = "" $arch = ""
@ -75,7 +60,20 @@ try {
$socket = "$($details.SocketDesignation) socket, " $socket = "$($details.SocketDesignation) socket, "
} }
$cores = [System.Environment]::ProcessorCount $cores = [System.Environment]::ProcessorCount
Write-Progress -completed " " $celsius = GetCPUTemperature
if ($celsius -eq 99999.9) {
$temp = "no temp"
} elseif ($celsius -gt 50) {
$temp = "$($celsius)°C"
$status = "⚠️"
} elseif ($celsius -lt 0) {
$temp = "$($celsius)°C"
$status = "⚠️"
} else {
$temp = "$($celsius)°C"
}
Write-Progress -completed "Done."
Write-Host "$status $cpuName ($($arch)$cores cores, $($deviceID)$($speed)$($socket)$temp)" Write-Host "$status $cpuName ($($arch)$cores cores, $($deviceID)$($speed)$($socket)$temp)"
exit 0 # success exit 0 # success
} catch { } catch {