0

this script was working perfectly yesterday but today (after pc restart) all of a sudden stopped working.

kinda working but only CPU usage and CPU E-Core average is posting, any other sensors not posting.

and theres some difference between running manually and run by application like: powershell.exe -f monitor.ps1



# Load the LibreHardwareMonitorLib.dll

$dll = "LibreHardwareMonitorLib.dll"

# Unblock the DLL file

Unblock-File -LiteralPath $dll

# Load the DLL

Add-Type -LiteralPath $dll

# Create an instance of the Computer class from the DLL

$computer = New-Object LibreHardwareMonitor.Hardware.Computer

$computer.IsCpuEnabled = $true

$computer.IsGpuEnabled = $true

$computer.IsStorageEnabled = $true

# Initialize the hardware monitoring

$computer.Open()

$targetCores = 7..10

# Iterate through the hardware to find the CPU and the corresponding power sensor

while ($true) {

    #CPU TOTAL USAGE

    foreach ($hardware in $computer.Hardware) {

        if ($hardware.HardwareType -eq "Cpu") {

            $hardware.Update()

    

            foreach ($sensor in $hardware.Sensors) {

                if ($sensor.SensorType -eq "Load" -and $sensor.Name -like "CPU Total") {

                    $cpuload = $([math]::Round($sensor.Value))   

                }

            }

        }

    }

    #CPU PACKAGE POWER

    foreach ($hardware in $computer.Hardware) {

        if ($hardware.HardwareType -eq "Cpu") {

            $hardware.Update()

            foreach ($sensor in $hardware.Sensors) {

                if ($sensor.SensorType -eq "Power" -and $sensor.Name -like "*Package*") {

                    $cpup = $([math]::Round($sensor.Value))

                }

            }

        }

    }

    #CPU PACKAGE TEMPERATURE

    foreach ($hardware in $computer.Hardware) {

        if ($hardware.HardwareType -eq "Cpu") {

            $hardware.Update()

            foreach ($sensor in $hardware.Sensors) {

                if ($sensor.SensorType -eq "Temperature" -and $sensor.Name -like "CPU Package") {

                    $cput = $($sensor.Value)

                }

            }

        }

    }

    #E-CORE AVERAGE USAGE

    $totalLoad = 0

    $coreCount = 0

    foreach ($hardware in $computer.Hardware) {

        # Loop through each sensor in the hardware component

        foreach ($sensor in $hardware.Sensors) {

            # Check if the sensor is a load sensor and if it represents a CPU core

            if ($sensor.SensorType -eq 'Load' -and $sensor.Name -match 'CPU Core #(\d+)') {

                # Extract the core number from the sensor name

                $coreNumber = [int] $matches[1]

                # Check if the core number is within the target range

                if ($targetCores -contains $coreNumber) {

                    # Print the load value of the core

                

                    # Add the load to the total

                    $totalLoad += $sensor.Value

                    # Increment the core count

                    $coreCount++

                }

            }

        }

    }

    if ($coreCount -gt 0) {

        $cpue = $([math]::Round($totalLoad / $coreCount))

    }

    #GPU PACKAGE POWER

    foreach ($hardware in $computer.Hardware) {

        if ($hardware.HardwareType -eq "GpuNvidia" -or $hardware.HardwareType -eq "GpuAmd") {

            $hardware.Update()  # Update the sensor values

        

            # Loop through the sensors to find the GPU Power (Wattage) sensor

            foreach ($sensor in $hardware.Sensors) {

                if ($sensor.SensorType -eq "Power") {

                    $gpup = $([math]::Round($sensor.Value)) 

                }

            }

        }

    }

    #GPU NVEDC LOAD

    foreach ($hardware in $computer.Hardware) {

        if ($hardware.HardwareType -eq [LibreHardwareMonitor.Hardware.HardwareType]::GpuNvidia) {

            $hardware.Update()  # Refresh hardware data

        

            foreach ($sensor in $hardware.Sensors) {

                # Look for "D3D Video Decode" load sensor

                if ($sensor.Name -eq "D3D Video Decode" -and $sensor.SensorType -eq [LibreHardwareMonitor.Hardware.SensorType]::Load) {

                    $nvencUsage = [math]::Round($sensor.Value)  # Round the usage value

                }

            }

        }

    }

    #SSD STORAGE TEMPERATURE

    foreach ($hardware in $computer.Hardware) {

        if ($hardware.HardwareType -eq [LibreHardwareMonitor.Hardware.HardwareType]::Storage -and $hardware.Name -eq "CT500P3PSSD8") {

            $hardware.Update()  # Refresh hardware data

        

            foreach ($sensor in $hardware.Sensors) {

                # Look for temperature sensor for the specific storage

                if ($sensor.Name -eq "Temperature" -and $sensor.SensorType -eq [LibreHardwareMonitor.Hardware.SensorType]::Temperature) {

                    $storageTemp = [math]::Round($sensor.Value)  # Round the temperature value

                }

            }

        }

    }

    

    $output = "{0};{1};{2};{3};{4};{5};{6}" -f $cpuload, $cpup, $cput, $cpue, $gpup, $nvencUsage, $storageTemp

    cls

    Write-Output $output

    Get-ExecutionPolicy

    Write-Output "DLL Loaded: $([System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.FullName -match 'LibreHardwareMonitor' })"

 

    Start-Sleep -Seconds 1

    

}

# Close the hardware monitoring

$computer.Close()


ive tried to unblock the dll but no success

1
  • Which is the problem? And which difference running it manually?
    – Nifriz
    Commented Oct 10, 2024 at 9:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.