Created
May 6, 2014 02:02
-
-
Save vScripter/7cff9005adebab9083f8 to your computer and use it in GitHub Desktop.
Saturate selected or all CPU cores for utilization stress testing, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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