Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## This will get the processor temperature from WMI and optionally log to a file with DTG
- ## Usage:
- ##
- ## Get-Temperature [-logfile %LOGFILELOCATION%]
- ## -logfile is optional - if it is left out, the output will be displayed on the screen
- ##
- ## eg:
- ## Get-Temperature
- ## Get-Temperature -logfile "h:\TempLog.csv"
- # You **must** run as Administrator.
- #Credit for the WMI part to Jeff Ammons : http://ammonsonline.com/is-it-hot-in-here-or-is-it-just-my-cpu/
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory=$False)]
- [string]$logFile
- )
- #Use WMI to get the temperature.
- $WMITemperature = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
- #There may be more than 1 sensor, so use foreach to go through each one
- foreach($Instance in $WMITemperature){
- #The temperature is in Kelvin - multiplied by 10, so divide by 10 and convert to C (subtract 273.16)
- $TempInCelcius = $Instance.CurrentTemperature /10-273.16
- $DTGdate=get-date -UFormat "%Y/%m/%d"
- $DTGtime=get-date -UFormat "%R" # %R is 24 hour time
- $TemperatureObject =new-object PSObject # Create a new object to store the values to allow an easy export
- $TemperatureObject | Add-member -membertype NoteProperty -name DTGdate -Value $DTGdate
- $TemperatureObject | Add-member -membertype NoteProperty -name DTGtime -Value $DTGtime
- $TemperatureObject | Add-member -membertype NoteProperty -name TempSensor -Value $Instance.InstanceName
- $TemperatureObject | Add-member -membertype NoteProperty -name TempC -value $TempInCelcius
- if ($logFile -eq "")
- {
- $TemperatureObject # If no filepath was specified, output to screen
- }
- else
- {
- $temperatureObject | export-csv -NoTypeInformation -path $logfile -append -force # Output to file
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement