PowerShell: Change the Color of the Prompt

Updated post here: https://codeyarns.github.io/tech/2011-09-02-powershell-change-the-color-of-the-prompt.html

7 thoughts on “PowerShell: Change the Color of the Prompt

    1. BasBunia: Notice that the TechNet article shows you how to change the colors of the entire PowerShell console. This is not what I want! I want to change only the color of the PowerShell prompt to yellow, the rest of the text remains white. (See screenshot above.)

      Like

  1. Thanks for the code

    I’ve changed it a little for my needs, so I have the username and current time in the prompt – here’s my change:
    #############################
    #function prompt {“[$env:USERNAME @$(get-date -format HH:mm:ss)] PS> “}

    function Prompt
    {
    $promptString = “[$env:USERNAME @$(get-date -format HH:mm:ss)] PS> ”
    Write-Host $promptString -NoNewline -ForegroundColor Yellow
    return ” ”
    }

    ############################
    Behind the comment in the code is my previous line I used for PS.
    I’m still looking for a way to get the PWD into the title bar of PS – having it in the prompt might get annoying the more I descend into subdirs. I might come back here if I find a solution for that.

    Please note I’m not a scripting pro – so anyone out there please keep it in mind before you apply my changes. The snippet seems to work here tho’, so it seems being smoke tested. Maybe .. :]

    Again, Thanks!

    Regards
    Wolfgang

    Like

  2. A trick I use to conserve screen real-estate in the working area of the window…

    function Prompt
    {
    $promptString = “PS>”
    Write-Host $promptString -NoNewline -ForegroundColor Yellow
    $host.ui.rawui.WindowTitle = “PowerShell [” + $(Get-Location) + “]”
    return ” ”
    }

    Joe

    Like

  3. my prompt is ” [Username dir]$ ” and it is colored perfectly with your code, I just want to color the dir a different color, how can I do that?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.