Skip to content

Instantly share code, notes, and snippets.

@vScripter
Created May 6, 2014 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vScripter/7cff9005adebab9083f8 to your computer and use it in GitHub Desktop.
Save vScripter/7cff9005adebab9083f8 to your computer and use it in GitHub Desktop.
Saturate selected or all CPU cores for utilization stress testing, etc.
[cmdletbinding()]
param(
[parameter(mandatory=$true)]
[int]$NumHyperCores
)
$Log = "C:\CPUStressTest.ps1.log"
$StartDate = Get-Date
Write-Output "============= CPU Stress Test Started: $StartDate =============" >> $Log
Write-Output "Started By: $env:username" >> $Log
Write-Warning "This script will potentially saturate CPU utilization!"
$Prompt = Read-Host "Are you sure you want to proceed? (Y/N)"
if ($Prompt -eq 'Y')
{
Write-Warning "To cancel execution of all jobs, close the PowerShell Host Window."
Write-Output "Hyper Core Count: $NumHyperCores" >> $Log
foreach ($loopnumber in 1..$NumHyperCores){
Start-Job -ScriptBlock{
$result = 1
foreach ($number in 1..2147483647){
$result = $result * $number
}# end foreach
}# end Start-Job
}# end foreach
Wait-Job *
Clear-Host
Receive-Job *
Remove-Job *
}# end if
else{
Write-Output "Cancelled!"
}
$EndDate = Get-Date
Write-Output "============= CPU Stress Test Complete: $EndDate =============" >> $Log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment