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
- Each loop runs as a separate background job, not as a thread in the current session.
- The jobs keep consuming CPU until they are stopped, so run
Get-Job | Stop-Jobwhen the test is finished. - Only run this script on a test machine, never on a production server.