Get CPU temperature in CMD/POWER Shell

后端 未结 5 1999
暖寄归人
暖寄归人 2020-12-18 00:48

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 M         


        
5条回答
  •  半阙折子戏
    2020-12-18 01:11

    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
    

提交回复
热议问题