CPU Temp

Import-Module $SuperOpsModule

$Date = Get-Date
Write-Host This script ran on $Date
Add-Content c:\SPI\ScriptHistory.txt "Temp-Probe Script Ran on $Date"

$warningTemp = 180
$alarmTemp = 185


$probeInstalled = Test-Path -Path "C:\temp\temp-probe"
If ($probeInstalled){ 
    Write-Host "Installed - running the probe"    
    Start-Process  -FilePath "C:\temp\temp-probe\TempProber.exe" -NoNewWindow -Wait -RedirectStandardOutput C:\temp\temp-probe\temperature.txt  -RedirectStandardError C:\temp\temp-probe\temperature_error.txt 
} ELSE { 
    Write-Host "Unzipping first.."
    Expand-Archive C:\temp\temp-probe.zip -DestinationPath C:\temp\temp-probe
    Write-Host "running the probe"
    Start-Process  -FilePath "C:\temp\temp-probe\TempProber.exe" -NoNewWindow -Wait -RedirectStandardOutput C:\temp\temp-probe\temperature.txt  -RedirectStandardError C:\temp\temp-probe\temperature_error.txt
}

$result = gc C:\temp\temp-probe\temperature.txt
$cpuLine = $result -match "CPU"

IF ($cpuLine) {
    $temperature = $cpuline | select-string -pattern '\d+' -allmatches  | % { $_.Matches } | % { $_.Value }
    
Send-CustomField -CustomFieldName "CPU Temp" -Value $temperature

    IF ([int]$temperature -gt $alarmTemp){
        write-host "Host is HOT!"  
                exit
    }
    ELSEIF ([int]$temperature -gt $warningTemp){
        write-host "Host is warming up..."    
    }
    ELSE {
        write-host "Just chilling at $temperature currently..."
        }
    
} ELSE {
    write-host "Could not find a CPU result from openhardwaremonitor"
}

#Clean up our temp file on the way out!
Remove-Item "C:\temp\temp-probe\temperature.txt"

Script data

Language - PowerShell

Run as - System / Root User

Script timeout duration - 5 Mins

Read me

If importing this in, need to download the temp-probe zip file from https://github.com/MikeLierman/TempProber. To take this a step further, create a custom field called CPU Temp in your Windows Asset Group and this will populate that field.