Skip to content

Instantly share code, notes, and snippets.

Last active December 16, 2015 18:50
What would you like to do?

Installation (Quick Start)

To install the prompt, run the following PowerShell command:

iex (New-Object Net.Webclient).DownloadString('')

That's it.


A PowerShell prompt that times how long each operation takes and displays the result at the command prompt. Measure-Command is great, but only useful if you had the presence of mind to run your long-running command within it.

A balloon will pop up in the notification area telling you of any tasks that take longer than 30 seconds to complete.

An example of what the command line looks like (playing nicely with PoshGit):

C:\Demo [master]> Start-Sleep 3
C:\Demo [master]> Start-Sleep 5
C:\Demo [master]>
C:\Demo [master]>

Known Issues

  • Autocompletion of path names etc. causes the PowerShell host to fire a Busy event, which prematurely sets of the timer, inflating the next timing measurement.
  • The notification icon is not disposed of when the PowerShell instance shuts down.
Starts a timer that automatically times how long operations take and displays elapsed time at the command prompt.
A notification balloon pops up if a task takes longer than 30 seconds.
Author: Bart Joy
function Start-TimerPrompt()
$ErrorActionPreference = 'Stop'
if(!$global:prompt_timer) {
$global:prompt_old = get-content function:\prompt
$className = 'StateChanged'
Add-Type -IgnoreWarnings @"
public class $className {
public System.Diagnostics.Stopwatch Timer { get; set; }
public $className(System.Management.Automation.Runspaces.Runspace runspace) {
runspace.AvailabilityChanged += (o,a) => {
if(runspace.RunspaceAvailability == System.Management.Automation.Runspaces.RunspaceAvailability.Busy && Timer == null)
Timer = System.Diagnostics.Stopwatch.StartNew();
$global:prompt_timer = New-Object $className $Host.Runspace
function global:Prompt()
if($global:prompt_timer) {
$timer = $global:prompt_timer.Timer
if($timer) {
$elapsed = $timer.Elapsed
Write-Host $elapsed
if($timer.ElapsedMilliseconds -gt 30 * 1000) {
Show-BalloonTip -Title "PowerShell Task Completed" -MessageType Info -Message "A long running task has completed." -Duration 10000
$global:prompt_timer.Timer = $null
& $global:prompt_old
function Show-BalloonTip(
[string][ValidateSet('None', 'Info', 'Warning', 'Error')]$MessageType = 'Info',
[int]$DurationInMilliseconds = 10000
$balloon = $global:notification_baloon
if(!$balloon) {
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon((Get-Process -Id $PID).Path)
$balloon = New-Object System.Windows.Forms.NotifyIcon
$balloon.Icon = $icon
$balloon.Visible = $true
$global:notification_baloon = $balloon
$balloon.BalloonTipIcon = $MessageType
$balloon.BalloonTipText = $Message
$balloon.BalloonTipTitle = $Title
This script is only intended for easy installation via Github Gist. It is not required for normal operation of the tool.
See 1-Installation.markdown for installation instructions.
$profileDir = Split-Path -Parent $profile
$moduleFile = Join-Path $profileDir 'TimerPrompt.psm1'
(new-object net.webclient).DownloadFile('', $moduleFile)
$command = 'ipmo $PSScriptRoot\TimerPrompt.psm1'
$content = cat $profile -ErrorAction SilentlyContinue
if($content -notcontains $command) {
$content += "`r`n`r`n$command`r`nStart-TimerPrompt`r`n"
$content | Set-Content -Path $profile -Encoding UTF8
& $profile
Write-Host 'TimerPrompt successfully installed.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment