Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get CPU Temperature With PowerShell
function Get-Temperature {
$t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$currentTempKelvin = $t.CurrentTemperature / 10
$currentTempCelsius = $currentTempKelvin - 273.15
$currentTempFahrenheit = (9/5) * $currentTempCelsius + 32
return $currentTempCelsius.ToString() + " C : " + $currentTempFahrenheit.ToString() + " F : " + $currentTempKelvin + "K"
}
# Save in your c:\users\yourName\Documents\WindowsPowerShell\modules\ directory
# in sub directory get-temperature as get-temperature.psm1
# You **must** run as Administrator.
# It will only work if your system & BIOS support it. If it doesn't work, I can't help you.
# Just type get-temperature in PowerShell and it will spit back the temp in Celsius, Farenheit and Kelvin.
# More info on my blog: http://ammonsonline.com/is-it-hot-in-here-or-is-it-just-my-cpu/
@teukkam

This comment has been minimized.

Copy link

teukkam commented Jan 27, 2015

On my PC (running Windows 8) $t.CurrentTemperature returns an array of 6 values instead of a single value. Thus, I modified the script as follows:

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
}
@DanielGGordon

This comment has been minimized.

Copy link

DanielGGordon commented Feb 8, 2016

@jefa00 Hmm this always returns the same temperature for me: 2982 (I assume this is really supposed to be 298.2 Kelvin). I put a load on my cpu, and this number does not change for me.

I'm calling powershell from Git Bash for Windows.

@tuefekci

This comment has been minimized.

Copy link

tuefekci commented Feb 11, 2016

I get ´-273.15 C : -459.67 F : 0K´ diddnt looked much into if i can fix it but this thematic is really pain on windows.

@1RedOne

This comment has been minimized.

Copy link

1RedOne commented Apr 19, 2016

I really like this. I'll be using this logic to make a systemtray temperature monitor, I'll let you know how it progresses :)

@ashishpatel1992

This comment has been minimized.

Copy link

ashishpatel1992 commented Apr 26, 2016

My System result
-273.15 C : -459.67 F : K
Looks like something wrong with calculations

@djflux

This comment has been minimized.

Copy link

djflux commented May 4, 2016

I had the same experience as teukkam however that code doesn't seem to work either. Here is code that WorksForMe(tm) on Windows 7 (returning an array of 6 values):

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

    foreach ($temp in $t)
    {
        $currentTempKelvin = $temp.CurrentTemperature / 10
        $currentTempCelsius = $currentTempKelvin - 273.15

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

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

If you get Get-WmiObject: Access denied error then you need to start your PowerShell instance as a local administrator. Even if you're a local admin, if you have UAC turned on you may receive this error so right-click on the PowerShell icon and select Run as Administrator

@DanielGGordon

This comment has been minimized.

Copy link

DanielGGordon commented May 18, 2016

powershell.exe Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" for me returns this:

__GENUS              : 2
__CLASS              : MSAcpi_ThermalZoneTemperature
__SUPERCLASS         : MSAcpi
__DYNASTY            : MSAcpi
__RELPATH            : MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\Therma
                       lZone\\THM__0"
__PROPERTY_COUNT     : 12
__DERIVATION         : {MSAcpi}
__SERVER             : 2USLGORDON
__NAMESPACE          : root\wmi
__PATH               : \\2USLGORDON\root\wmi:MSAcpi_ThermalZoneTemperature.Inst
                       anceName="ACPI\\ThermalZone\\THM__0"
Active               : True
ActiveTripPoint      : {0, 0, 0, 0...}
ActiveTripPointCount : 0
CriticalTripPoint    : 3802
CurrentTemperature   : 2982
InstanceName         : ACPI\ThermalZone\THM__0
PassiveTripPoint     : 0
Reserved             : 0
SamplingPeriod       : 0
ThermalConstant1     : 0
ThermalConstant2     : 0
ThermalStamp         : 9
PSComputerName       : 2USLGORDON

The only temp returned is 2982 - and it never changes from that value. I don't know if this is because I'm running it from git bash

@ctmcisco

This comment has been minimized.

Copy link

ctmcisco commented Mar 1, 2018

This outputs the system temp not the CPU Temp. I also had two Thermal zones and had to modify the script to only figure out that the wmi class was not for the CPU temp.

function Get-Temperature {
$t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" | where -Property instancename -EQ "ACPI\ThermalZone\TZ01_0"

$currentTempKelvin = $t.CurrentTemperature / 10
$currentTempCelsius = $currentTempKelvin - 273.15

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

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

}

PS C:\WINDOWS\system32> get-temperature
26.85 C : 80.33 F : 300K

@ctmcisco

This comment has been minimized.

Copy link

ctmcisco commented Mar 1, 2018

image

@justjim1220

This comment has been minimized.

Copy link

justjim1220 commented Oct 27, 2018

@ctmcisco

how did you get this resulting chart?

@justjim1220

This comment has been minimized.

Copy link

justjim1220 commented Oct 27, 2018

Anyone know how to pull the results from powershell output into a separate application?

OR...

How to get these results with nodejs and/or javascript?

@lenoln

This comment has been minimized.

Copy link

lenoln commented Aug 27, 2019

Hi, I'm using this away:
Temp in Cº
WMI
`$objWMi = get-wmiobject -namespace root\cimv2 -computername localhost -Query "Select * from Win32_PerfFormattedData_Counters_ThermalZoneInformation WHERE Name like '%GFXZ%'"

foreach ($obj in $objWmi)
{
write-host "######## INICIO Win32_PerfFormattedData_Counters_ThermalZoneInformation"
write-host "Caption:" $obj.Caption
write-host "Description:" $obj.Description
write-host "Frequency_Object:" $obj.Frequency_Object
write-host "Frequency_PerfTime:" $obj.Frequency_PerfTime
write-host "Frequency_Sys100NS:" $obj.Frequency_Sys100NS
write-host "Name:" $obj.Name
write-host "PercentPassiveLimit:" $obj.PercentPassiveLimit
write-host "Temperature:" (($obj.Temperature -273.15))
write-host "ThrottleReasons:" $obj.ThrottleReasons
write-host "Timestamp_Object:" $obj.Timestamp_Object
write-host "Timestamp_PerfTime:" $obj.Timestamp_PerfTime
write-host "Timestamp_Sys100NS:" $obj.Timestamp_Sys100NS
write-host
write-host "######## INICIO Win32_PerfFormattedData_Counters_ThermalZoneInformation"
write-host

}`

I hope I helped you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.