Change the PowerShell Prompt

It can be useful to see when you ran a command in PowerShell. You could run Get-Date each time, but that gets a little tedious.

Instead, you can change the “PS >” part of the prompt. First, try displaying the current time in the prompt.

1
Set-Item function:Global:prompt {"PS: $(Get-Date)>"} -force
PowerShell prompt displaying the current time

You can also color the prompt to give it an Exchange Management Shell-style look.

1
Set-Item function:global:prompt {$cwd = (Get-Location).Path; $host.UI.Write("Yellow", $host.UI.RawUI.BackgroundColor, "[PS]"); " $cwd>"}
PowerShell prompt displaying a yellow [PS] label and the current path

If a long path leaves too little room to enter a command, you can put the path on a separate line.

1
Set-Item function:global:prompt {$host.UI.WriteLine((Get-Location).Path); $host.UI.Write("Yellow", $host.UI.RawUI.BackgroundColor, "[PS]"); ">" }
PowerShell prompt displaying the current path on the first line

To check the current prompt definition, run this command:

1
(Get-Item function:prompt).Definition

To restore the original prompt, restart PowerShell.

Advertisement