PS ISE – Measure Script speed

Quick and easy way to measure execution time on a script, add the following to Microsoft.PowerShellISE_profile.ps1

Function Run-VerboseMeasured {
    PARAM (
    Write-Host "INFO: Running:  . '$($scriptFullPath)' -Verbose" -ForegroundColor Green
    $m = Measure-Command {Invoke-Expression -Command ". '$($scriptFullPath)' -Verbose"}

    if( $m.TotalSeconds -gt 10) {
        Write-Host "INFO: Script took $($m.TotalSeconds) sec to run" -ForegroundColor Green
    } else {
        Write-Host "INFO: Script took $($m.TotalMilliseconds) ms to run" -ForegroundColor Green


$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Run with -Verbose (measured)', { Run-VerboseMeasured $psISE.CurrentFile.FullPath }, 'Ctrl+F5') | Out-Null

Then, restart ISE and now you can Add-ons you will have a new menu item. 🙂