PowerShell – Check Temperature of CPU

email me

Clear-Host

$temperatures = ""
$Fahrenheit = ""
$temperatures = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | Select-Object -Property InstanceName,CurrentTemperature | where InstanceName -eq "ACPI\ThermalZone\CPUZ_0"

$Fahrenheit = [math]::round((9/5) * ($temperatures.CurrentTemperature / 10 - 273.15) + 32)

Write-host "Current Temperature: $Fahrenheit F"

if ($Fahrenheit -gt 190) {

Write-Host "Shutting down..."
# Stop-Computer -Force

}

 

 

Notes

You may need to modify ACPI\ThermalZone\CPUZ_0 to ACPI\ThermalZone\CPUZ_1…2…3, etc., until you find the appropriate CPU. Other CPUs may be listed as TZ0__0, TZ00_0, TZ001_0, THM0_0.

Idea:
Add script to task scheduler as a task (check every 15 to 30 minutes, or so). If your laptop comes on inside your bag and gets hot, it will shutdown automatically.

Performs somewhat slower:
Get-CimInstance -Namespace root/WMI -ClassName MSAcpi_ThermalZoneTemperature

Celsius:
https://stackoverflow.com/questions/39738494/get-cpu-temperature-in-cmd-power-shell

 

[math]::round

Number.Round

Get-WmiObject

Select-Object

Write-Host

 

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\HEPZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\HEPZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 0
CurrentTemperature : 3032
InstanceName : ACPI\ThermalZone\HEPZ_0
PassiveTripPoint : 0
Reserved : 0
SamplingPeriod : 0
ThermalConstant1 : 0
ThermalConstant2 : 0
ThermalStamp : 17
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\CPUZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\CPUZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 3582
InstanceName : ACPI\ThermalZone\CPUZ_0
PassiveTripPoint : 0
Reserved : 0
SamplingPeriod : 0
ThermalConstant1 : 0
ThermalConstant2 : 0
ThermalStamp : 20
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\GFXZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\GFXZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 2732
InstanceName : ACPI\ThermalZone\GFXZ_0
PassiveTripPoint : 3732
Reserved : 0
SamplingPeriod : 300
ThermalConstant1 : 1
ThermalConstant2 : 2
ThermalStamp : 18
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\EXTZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\EXTZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 3172
InstanceName : ACPI\ThermalZone\EXTZ_0
PassiveTripPoint : 0
Reserved : 0
SamplingPeriod : 0
ThermalConstant1 : 0
ThermalConstant2 : 0
ThermalStamp : 21
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\LOCZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\LOCZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 3172
InstanceName : ACPI\ThermalZone\LOCZ_0
PassiveTripPoint : 0
Reserved : 0
SamplingPeriod : 0
ThermalConstant1 : 0
ThermalConstant2 : 0
ThermalStamp : 19
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\BATZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\BATZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 3032
InstanceName : ACPI\ThermalZone\BATZ_0
PassiveTripPoint : 4012
Reserved : 0
SamplingPeriod : 300
ThermalConstant1 : 50
ThermalConstant2 : 0
ThermalStamp : 18
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\CHGZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\CHGZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 3272
InstanceName : ACPI\ThermalZone\CHGZ_0
PassiveTripPoint : 0
Reserved : 0
SamplingPeriod : 0
ThermalConstant1 : 0
ThermalConstant2 : 0
ThermalStamp : 16
PSComputerName : Demo-PC

__GENUS : 2
__CLASS : MSAcpi_ThermalZoneTemperature
__SUPERCLASS : MSAcpi
__DYNASTY : MSAcpi
__RELPATH : MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\PCHZ_0″
__PROPERTY_COUNT : 12
__DERIVATION : {MSAcpi}
__SERVER : Demo-PC
__NAMESPACE : root\wmi
__PATH : \\Demo-PC\root\wmi:MSAcpi_ThermalZoneTemperature.InstanceName=”ACPI\\ThermalZone\\PCHZ_0″
Active : True
ActiveTripPoint : {0, 0, 0, 0…}
ActiveTripPointCount : 0
CriticalTripPoint : 4012
CurrentTemperature : 2732
InstanceName : ACPI\ThermalZone\PCHZ_0
PassiveTripPoint : 0
Reserved : 0
SamplingPeriod : 0
ThermalConstant1 : 0
ThermalConstant2 : 0
ThermalStamp : 16
PSComputerName : Demo-PC

 

tags: PowerShell scripting, MrNetTek