Skip to content

Instantly share code, notes, and snippets.

@jeffa00
Last active April 19, 2024 20:06
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jeffa00/9577816 to your computer and use it in GitHub Desktop.
Save jeffa00/9577816 to your computer and use it in GitHub Desktop.
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/
@lenoln
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

@JosephLerouxBook
Copy link

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.

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

To all the people that have some trouble with it returning negatives values:

From what i understood, " Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" " can return more than one value, that is why we should get the information in an array.
I changed :
$t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
into :
$t = (Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi")[0]
And it now return the right value (37,05°c for me here).

Sorry for my poor english and maybe a bit late answer, but i hope it will help next ones !

@forthrin
Copy link

Hi!

I'd like to track CPU hogs over a day and get output in the following format. Unfortunately I have no Power Shell knowledge. Could you throw together something based on the snippets already here? I think this would be really useful for many people.

Pseudo:

while(TRUE)
  for each process that uses more than 5% cpu
    print datetime + cputemp + process.cpu + process.path
  sleep(5)

2020-05-01 12:34:56  34C  15%  C:\Program Files\Microsoft Office\msword.exe
2020-05-01 12:34:56  34C  11%  C:\Program Files\Microsoft Office\msexcel.exe
2020-05-01 12:41:10  37C   7%  C:\Program Files\Microsoft Office\mspoint.exe

@FatherDivine
Copy link

Doesn't seem to work on Winblows nowadays (At least 11, possibly 10). That's using PowerShell && pwsh:

Get-WmiObject : Not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment