# Read system thermal zones via WMI (if supported by your BIOS/driver)
# Run as Administrator for best chance. Output saved to .txt in same folder.
# If no data appears, use HWiNFO or Core Temp - see "Temperature monitoring guide" in this folder.

$ReportDir = $PSScriptRoot
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$LogFile = Join-Path $ReportDir "TemperatureLog_$Timestamp.txt"

$lines = @()
$lines += "Temperature check at $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
$lines += "Computer: $env:COMPUTERNAME"
$lines += ""

try {
    $zones = Get-CimInstance -Namespace "root/wmi" -ClassName MSAcpi_ThermalZoneTemperature -ErrorAction Stop
    if (-not $zones -or $zones.Count -eq 0) {
        $lines += "No thermal zones reported (BIOS/driver may not expose temperature via WMI)."
        $lines += "Use HWiNFO or Core Temp - see Temperature monitoring guide in this folder."
    }
    else {
        $idx = 0
        foreach ($z in $zones) {
            $idx++
            $kelvin10 = $z.CurrentTemperature
            if ($null -eq $kelvin10 -or $kelvin10 -eq 0) {
                $lines += "Zone $idx : Not supported or zero"
                continue
            }
            $celsius = ($kelvin10 / 10.0) - 273.15
            $lines += "Zone $idx : $([Math]::Round($celsius, 1)) C  (raw $kelvin10)"
        }
    }
}
catch {
    $lines += "WMI read failed: $($_.Exception.Message)"
    $lines += "Use HWiNFO or Core Temp - see Temperature monitoring guide in this folder."
}

$text = $lines -join "`r`n"
$text | Set-Content -Path $LogFile -Encoding UTF8
Write-Host $text
Write-Host ""
Write-Host "Log saved to: $LogFile" -ForegroundColor Green
