Setting PowerShell Title Text

by Jul 14, 2017

You probably know that you can change the title text of a PowerShell host window with a line like this:

PS> $host.UI.RawUI.WindowTitle = "Hello  World!" 

When you add this to your prompt function, the title text can be dynamic:

function prompt
    # get current path
    $path = Get-Location

    # get current time
    $date = Get-Date -Format 'dddd, MMMM dd'

    # create title text
    $host.UI.RawUI.WindowTitle = ">>$path<< [$date]"

    # output prompt
    'PS> '

The function “prompt” is executed each time PowerShell completes processing of a command. In your title bar, you’ll now always see your current path and the date, and the prompt inside the PowerShell editor is shortened to “PS> “.

Twitter This Tip! ReTweet this Tip!