daily pastebin goal
11%
SHARE
TWEET

Get Processor Temperature from Powershell

anonit Dec 28th, 2014 211 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. ## This will get the processor temperature from WMI and optionally log to a file with DTG
  2.  
  3.  
  4. ## Usage:
  5. ##
  6. ## Get-Temperature [-logfile %LOGFILELOCATION%]
  7. ## -logfile is optional - if it is left out, the output will be displayed on the screen
  8. ##
  9. ## eg:
  10. ## Get-Temperature
  11. ## Get-Temperature -logfile "h:\TempLog.csv"
  12.  
  13. # You **must** run as Administrator.
  14.  
  15. #Credit for the WMI part to Jeff Ammons : http://ammonsonline.com/is-it-hot-in-here-or-is-it-just-my-cpu/
  16.  
  17.  
  18. [CmdletBinding()]
  19. Param(
  20.    [Parameter(Mandatory=$False)]
  21.    [string]$logFile
  22. )
  23.  
  24. #Use WMI to get the temperature.  
  25.  
  26. $WMITemperature = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
  27.  
  28. #There may be more than 1 sensor, so use foreach to go through each one
  29. foreach($Instance in $WMITemperature){
  30.    
  31.     #The temperature is in Kelvin - multiplied by 10, so divide by 10 and convert to C (subtract 273.16)
  32.     $TempInCelcius = $Instance.CurrentTemperature /10-273.16
  33.     $DTGdate=get-date -UFormat "%Y/%m/%d"
  34.     $DTGtime=get-date -UFormat "%R"   # %R is 24 hour time
  35.  
  36.     $TemperatureObject =new-object PSObject   # Create a new object to store the values to allow an easy export
  37.     $TemperatureObject | Add-member -membertype NoteProperty -name DTGdate -Value $DTGdate
  38.     $TemperatureObject | Add-member -membertype NoteProperty -name DTGtime -Value $DTGtime
  39.     $TemperatureObject | Add-member -membertype NoteProperty -name TempSensor -Value $Instance.InstanceName
  40.     $TemperatureObject | Add-member -membertype NoteProperty -name TempC -value $TempInCelcius
  41.     if ($logFile -eq "")
  42.     {
  43.         $TemperatureObject   # If no filepath was specified, output to screen
  44.     }
  45.     else
  46.     {
  47.         $temperatureObject | export-csv -NoTypeInformation -path $logfile -append -force   # Output to file
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top