Under Review

Live Response: Temperature of a machine

  REVIEWED by Sophos 

In Celsius

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

function Get-Temperature {

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

foreach ($temp in $t.CurrentTemperature)
{


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

$returntemp += $currentTempCelsius.ToString() + " " + [char]0x00B0 + "C"
}
return $returntemp
}


Get-Temperature

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

 

In Fahrenheit

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

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() + " " + [char]0x00B0 + "C"
}
return $returntemp
}

Get-Temperature

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

  • With time:

    function Get-Temperature {

    $t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
    $returntemp = @()
    $returnTime = Get-Date -UFormat %R
    foreach ($temp in $t.CurrentTemperature)
    {


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

    $returntemp += $currentTempCelsius.ToString() + " " + [char]0x00B0 + "C"
    }
    return $returnTime, $returntemp
    }

  • The second  [char]0x00B0 + "C" should obviously be  [char]0x00B0 + "F"