PoSH – CPU Stress Test

Note: This is a recovered post from my old blog. See how we recovered these posts using the Wayback Machine and AI tooling.

A script to stress test CPU on locked-down networks without internet access. I used this after hardware upgrades on servers that were physically separated from the internet - it runs a PowerShell job per thread/logical CPU to max out utilization. Press Enter to stop the test and clean up the jobs.

#Get thread count
$cores = ((get-counter "\Processor(*)\% idle time").countersamples | select instancename).length -1
# CPU Stress
$CPU = {
foreach ($loopnumber in 1..2147483647) {$result=1;foreach ($number in 1..2147483647) {$result = $result * $number};$result}
}
# Execute the jobs in parallel
$jobarray = New-Object System.Collections.ArrayList
$jobarray.Clear()
$jobnumber = 0
Foreach ($cores in 1..$cores) {
$jobnumber++
Start-Job $CPU -name "CPU_Stress$jobnumber"
$jobarray.Add("CPU_Stress$jobnumber")
Start-Sleep -Seconds 1
}
Read-Host "Press ENTER to stop the stress test"
Foreach ($job in $jobarray) {
Stop-Job $job
}