Updated check-cpu.ps1

This commit is contained in:
Markus Fleschutz 2024-10-14 16:27:54 +02:00
parent 6659468d18
commit 53381691df

View File

@ -55,31 +55,31 @@ try {
$details = Get-WmiObject -Class Win32_Processor $details = Get-WmiObject -Class Win32_Processor
$cpuName = $details.Name.trim() $cpuName = $details.Name.trim()
$arch = "$arch, " $arch = "$arch, "
$deviceID = "$($details.DeviceID), " $deviceID = ", $($details.DeviceID)"
$speed = "$($details.MaxClockSpeed)MHz, " $speed = ", $($details.MaxClockSpeed)MHz"
$socket = "$($details.SocketDesignation) socket" $socket = ", $($details.SocketDesignation) socket"
} }
$cores = [System.Environment]::ProcessorCount $cores = [System.Environment]::ProcessorCount
$celsius = GetCPUTemperature $celsius = GetCPUTemperature
if ($celsius -eq 99999.9) { if ($celsius -eq 99999.9) {
$temp = "no temp" $temp = ""
} elseif ($celsius -gt 80) { } elseif ($celsius -gt 80) {
$temp = "$($celsius)°C TOO HOT" $temp = ", $($celsius)°C TOO HOT"
$status = "⚠️" $status = "⚠️"
} elseif ($celsius -gt 50) { } elseif ($celsius -gt 50) {
$temp = "$($celsius)°C HOT" $temp = ", $($celsius)°C HOT"
$status = "⚠️" $status = "⚠️"
} elseif ($celsius -lt 0) { } elseif ($celsius -lt 0) {
$temp = "$($celsius)°C TOO COLD" $temp = ", $($celsius)°C TOO COLD"
$status = "⚠️" $status = "⚠️"
} elseif ($celsius -lt 30) { } elseif ($celsius -lt 30) {
$temp = "$($celsius)°C cool" $temp = ", $($celsius)°C cool"
} else { } else {
$temp = "$($celsius)°C OK" $temp = ", $($celsius)°C OK"
} }
Write-Progress -completed "Done." Write-Progress -completed "Done."
Write-Host "$status $cpuName ($($arch)$cores cores, $($deviceID)$($speed)$($socket)) - $temp" Write-Host "$status $cpuName ($($arch)$cores cores$($temp)$($deviceID)$($speed)$($socket))"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"