LLI Wiki — My Digital Knowledge Base

CPU stress test with PowerShell

PowerShell script that starts background jobs to load the CPU, with commands to list and stop them.

This short PowerShell script starts several background jobs, each running a tight loop, so that the CPU runs at full load. It can be used to check how a test machine behaves under sustained load (cooling, power supply, monitoring).

Script

# Set NumThreads to the number of cores your CPU has.
# If your CPU has HyperThreading, use the full thread count.
$NumThreads = 8

ForEach ($loop in 1..$NumThreads) {
    Start-Job -ScriptBlock {
        [float]$result = 1
        while ($true) {
            [float]$x = get-random -Minimum 1 -Maximum 999999999
            $result = $result * $x
        }
    }
}

Managing the jobs

# List all jobs
Get-Job

# List only running jobs
Get-Job | Where-Object { $_.State -eq 'Running' }

# Stop a single job
Get-Job Job17 | Stop-Job

# Stop all jobs
Get-Job | Stop-Job

Notes

Mastodon LLIMastodon SocialFosstodon