Saturday 29 August 2020

powershell 20 cpu stress test on remote computer

before stress test

during stress test

after stress test

 
invoke-command -session $session -scriptblock {
    function stress-cpu {
        [cmdletbinding()]
        param(
            [parameter(mandatory = $true)][int]$NumHyperCores
        )

        Write-Output "============= CPU Stress Test Started: $(get-date) ============="
        Write-Warning "This script will potentially max your 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" 
            Measure-Command {
                foreach ($loopnumber in 1..$NumHyperCores) {
                    Start-Job -ScriptBlock {
                        $result = 1
    
                        foreach ($number in 1..214748369) {
                            $result = $result * $number
                        }
                    }
                }

                Wait-Job *
                Clear-Host
                Receive-Job *
                Remove-Job * 
            }
        }
        else {
            Write-Output "Cancelled!"
        }
    }

    stress-cpu -NumHyperCores 8
}

-------------------------------------
#stop test

invoke-command -session $session -scriptblock {
    get-job | Stop-Job
}

No comments:

Post a Comment