20

In my computer I am trying to get the CPU temperature. Searching on StackOverflow I found this:

C:\WINDOWS\system32>wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature

But I get this error:

Node - ADMIN
ERROR:
Description = Not supported
SiHa
  • 7,830
  • 13
  • 34
  • 43
utkroza blue
  • 201
  • 1
  • 2
  • 3

6 Answers6

24

you can use this code :

function Get-Temperature {
    $t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
    $returntemp = @()

    foreach ($temp in $t.CurrentTemperature)
    {


    $currentTempKelvin = $temp / 10
    $currentTempCelsius = $currentTempKelvin - 273.15

    $currentTempFahrenheit = (9/5) * $currentTempCelsius + 32

    $returntemp += $currentTempCelsius.ToString() + " C : " + $currentTempFahrenheit.ToString() + " F : " + $currentTempKelvin + "K"  
    }
    return $returntemp
}

Get-Temperature
saftargholi
  • 896
  • 1
  • 9
  • 25
  • 12
    this is not direct CPU temp but somewhere on the MB: https://stackoverflow.com/a/17083409/1747983 – Tilo Oct 24 '18 at 20:00
  • 2
    Update for newer versions: `Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"` – Efren Sep 06 '21 at 04:07
5

You can use Open Hardware Monitor it's an open source software (MPL v2). You can access the command line version here:

OpenHardwareMonitorReport.zip

Example part of the output:

PS C:\Users\myuser\OpenHardwareMonitorReport> .\OpenHardwareMonitorReport.exe

Open Hardware Monitor Report

--------------------------------------------------------------------------------

Version: 0.8.0.2

--------------------------------------------------------------------------------

Common Language Runtime: 4.0.30319.42000
Operating System: Microsoft Windows NT 6.2.9200.0
Process Type: 32-Bit

--------------------------------------------------------------------------------

Sensors

|
+- HP 00F52W (/mainboard)
|
+- Intel Core i7-3770 (/intelcpu/0)
|  +- Bus Speed      :  99.7734  99.7734  99.7784 (/intelcpu/0/clock/0)
|  +- CPU Core #1    :  3691.62  3691.62  3791.58 (/intelcpu/0/clock/1)
|  +- CPU Core #2    :  3691.62  3691.62  3791.58 (/intelcpu/0/clock/2)
|  +- CPU Core #3    :  3791.39  3791.39  3891.36 (/intelcpu/0/clock/3)
|  +- CPU Core #4    :  3691.62  3691.62  3891.36 (/intelcpu/0/clock/4)
|  +- CPU Core #1    :       42       42       43 (/intelcpu/0/temperature/0)
|  +- CPU Core #2    :       43       37       43 (/intelcpu/0/temperature/1)
|  +- CPU Core #3    :       42       35       42 (/intelcpu/0/temperature/2)
|  +- CPU Core #4    :       45       41       45 (/intelcpu/0/temperature/3)
|  +- CPU Package    :       45       43       45 (/intelcpu/0/temperature/4)
uak
  • 183
  • 3
  • 9
5

Run the following command in Command Prompt as an Administrator:

wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature

This will give you some output like this:

CurrentTemperature 3000 3010

But make sure that you are running the cmd as an Administrator

n_y_1411
  • 59
  • 1
  • 1
  • 8
    Admin or no admin makes no difference. Apparently the query isn't supported on my Windows. – Jari Turkia Jan 10 '21 at 18:49
  • On my computer- CurrentTemperature 3000 3010 its how much in °C? – MILAN SAHANA Mar 21 '22 at 12:55
  • 1
    @MILANSAHANA it's in 10th of Kelvin so 3010 = 301.0 K = 27.85° C – Matthieu Jul 13 '22 at 09:42
  • This works, but is not the CPU temperature. Result is given in units of `C*10` to avoid floats from the sensor. So in this case you need to divide the sensor value by 10 and use that for K in `C = K - 273.15`. – not2qubit Jun 27 '23 at 07:02
3

On my laptop all above gave me wrong results. Only this one was showing the CPU-Temperature in Celsius:

$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
@($data)[0].HighPrecisionTemperature

I guess, that each CPU-version may have a different place/formular to get the correct CPU-temperature.

Carsten
  • 1,612
  • 14
  • 21
  • Interesting and nice twist, but not good for repeated run rates. The Query statement is slow. And don't expect to get the CPU core temp. – not2qubit Jun 27 '23 at 07:05
0

With new sensor, or with what I have and with elevation. It also shows critical temperature and percentage (in Celsius) It leaves a file Temperatures.txt for easy debugging, and the xml with serialized object from sensors

function Get-Temperature {
    $TempFormat = "#"
    $TempFile = "temperature"

    $Command = 'Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" ' + " > $pwd\$TempFile.txt"
    $Command = 'Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" ' + " | Export-Clixml $pwd\$TempFile.xml"

    $p = Start-Process -Verb runas -FilePath "powershell" -ArgumentList $command -WorkingDirectory $pwd -PassThru
    $p.WaitForExit()

    $t = Import-Clixml pippo.xml

    $returntemp = @()

    foreach ($Sensor in $t)
    {
    $Active = if($sensor.Active){"On "}else{"Off"}
    $temp = $Sensor.CurrentTemperature
    $Critical = $Sensor.CriticalTripPoint

    $currentTempKelvin = $temp / 10
    $currentTempCelsius = $currentTempKelvin - 273.15
    $currentTempFahrenheit = (9/5) * $currentTempCelsius + 32

    $StrKelvin = $currentTempKelvin.ToString($TempFormat).PadLeft(3, " ")
    $StrCelsius = $currentTempCelsius.ToString($TempFormat).PadLeft(3, " ")
    $StrFahrenheit = $currentTempFahrenheit.ToString($TempFormat).PadLeft(3, " ")

    $CriticalKelvin = $Critical / 10
    $CriticalCelsius = $CriticalKelvin - 273.15
    $CriticalFahrenheit = (9/5) * $CriticalCelsius + 32

    $StrCritKelvin = $CriticalKelvin.ToString($TempFormat).PadRight(3, " ")
    $StrCritCelsius = $CriticalCelsius.ToString($TempFormat).PadRight(3, " ")
    $StrCritFahrenheit = $CriticalFahrenheit.ToString($TempFormat).PadRight(3, " ")

    $PerCrit = ($currentTempCelsius/$CriticalCelsius * 100)
    $StrPerCrit = $PerCrit.ToString($TempFormat).PadLeft(3, " ")

    $returntemp += "$Active $StrPerCrit% $StrCelsius/$StrCritCelsius C : $StrFahrenheit/$StrCritFahrenheit  F : $StrKelvin/$StrCritKelvin K - " + $Sensor.InstanceName 
    }
    return $returntemp
}

Get-Temperature
-3

According to the answer on this question :

To get the exact temperature of CPU (and every core) you need to write kernel drivers, what is much more complicated.

CurrentTemperature returns temperature at some thermal zone which is somewhere on motherboard.

This would explain why some of the answers on this page return a temperature, but it's wildly different to the actual CPU temp.

KERR
  • 1,312
  • 18
  • 13