Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get CPU temperature in CMD/POWER Shell

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
like image 725
utkroza blue Avatar asked Sep 28 '16 05:09

utkroza blue


People also ask

How can I check the temp of my CPU?

Checking your CPU temperature is as easy as installing and using monitoring software and then reading the value. There are multiple programs to choose from, with the best tools for checking CPU temperature, including Core Temp (opens in new tab), NZXT's CAM (opens in new tab), AIDA64, HWiINFO, or HWMonitor.

How do I check CPU temp in terminal?

Open the terminal application. Run hddtemp command to see SSD and hard drive temperature in Ubuntu. Execute sensors command to find out CPU temperature in Ubuntu Linux.

How do I check my CPU temperature Windows?

If you'd like to see the CPU temperature in the taskbar, right-click the temperature itself and click “Show in Tray.” If the reading ends up hiding in the “additional” icons section, you can drag it onto the main active tray. This means it'll always be visible as long as you can see the taskbar.

Is there a way to get the CPU temperature through PowerShell?

With an external software like Core-Temp it is pretty easy to get the CPU temperature. But I would like to obtain the same data through PowerShell or cmd.exe, also for scripting purposes. The most useful discussion I've found is here, where the only information given is a link to Microsoft WMIC.

How to get the CPU temperature for each core in Linux?

As we can see, the CPU temperature for each core is given in the Core 0 and Core 1 fields, respectively. Moreover, if it doesn’t display the CPU temperature, we can run the sensors-detect command beforehand. The sensors-detect command will detect all the available sensors attached to the machine.

How to monitor the computer temperature in Windows 10?

As an Administrator, start a new POWERSHELL command-line prompt. Get the computer temperature. Here is the command output. In our example, we got the computer temperature in Celsius, Fahrenheit, and Kelvin. Optionally, Monitor the computer temperature using the command named TYPEPERF. Here is the command output.

How to get the correct CPU/Apu temperature?

If you have a Ryzen CPU/APU you need to install Ryzen Master to get the correct Temperatures. You can download the latest version from AMD Download page for your Ryzen CPU/APU. EDIT: Found this webpage with Powershell script for temperatures.


2 Answers

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
like image 99
saftargholi Avatar answered Oct 04 '22 05:10

saftargholi


You can get the CPU temp in both WMI and Open Hardware Monitor way.

Open Hardware Monitor:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenHardwareMonitor.Hardware;
namespace Get_CPU_Temp5
{
   class Program
   {
       public class UpdateVisitor : IVisitor
       {
           public void VisitComputer(IComputer computer)
           {
               computer.Traverse(this);
           }
           public void VisitHardware(IHardware hardware)
           {
               hardware.Update();
               foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
           }
           public void VisitSensor(ISensor sensor) { }
           public void VisitParameter(IParameter parameter) { }
       }
       static void GetSystemInfo()
       {
           UpdateVisitor updateVisitor = new UpdateVisitor();
           Computer computer = new Computer();
           computer.Open();
           computer.CPUEnabled = true;
           computer.Accept(updateVisitor);
           for (int i = 0; i < computer.Hardware.Length; i++)
           {
               if (computer.Hardware[i].HardwareType == HardwareType.CPU)
               {
                   for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                   {
                       if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                               Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                   }
               }
           }
           computer.Close();
       }
       static void Main(string[] args)
       {
           while (true)
           {
               GetSystemInfo();
           }
       }
   }
}

WMI:

using System;
using System.Diagnostics;
using System.Management;
class Program
{
   static void Main(string[] args)
   {
       Double CPUtprt = 0;
       System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(@"root\WMI", "Select * From MSAcpi_ThermalZoneTemperature");
       foreach (System.Management.ManagementObject mo in mos.Get())
       {
           CPUtprt = Convert.ToDouble(Convert.ToDouble(mo.GetPropertyValue("CurrentTemperature").ToString()) - 2732) / 10;
          Console.WriteLine("CPU temp : " + CPUtprt.ToString() + " °C");
       }
   }
}

I found a nice tutorial here, I get the CPU temp successfully.

http://www.lattepanda.com/topic-f11t3004.html

like image 30
haoming weng Avatar answered Oct 04 '22 05:10

haoming weng