Anders G. Nordby

Senior Systems Consultant at CGI

Monthly Archives: August 2013

Tweeking the PowerShell prompt

Just a quick note to self again, so I don’t loose this.

I’ve been working a bit with PowerShell lately, and one of the most useful things I’ve done is to tweek my colour scheme and my prompt. When a command spits out several screenfuls to my console window, it’s rather useful to use a different colour for the prompt and for the default output text; this makes it so much easier to find where the command started when I’m scrolling back up. Also, for long-running commands, it’s sometimes very handy to know when they where started, or how long they really took to run.

My chosen colours are somewhat retro; green on black for the regular text (and grey/yellow for the prompt).
I think this looks nice:
powershell-profile

My $profile code is this:

function prompt {
        $d = Get-Date -Format "yyyy-MM-dd HH:mm"
        Write-Host $d -NoNewline -ForegroundColor Gray
        Write-Host " $pwd" -NoNewline -ForegroundColor Yellow
        Write-Host -NoNewLine -ForegroundColor Gray " >"
        " "
}

Tip for newbies: If the $profile command returns a path to a file/directory that does not exist, just create it! (I had to create both the WindowsPowerShell directory and the Microsoft.PowerShell_profile.ps1 file.)