0

I use the following to wrap my location in:

function prompt 
{ 
    if ($isAdmin) 
    {
        "[" + (Get-Location) + "] # "
    }
    else 
    {
        "[" + (Get-Location) + "] $ "
    }
}

This renders a location listing like so:

Location

How can I color the location in using ForeGround color? I tried appending it but it did not work. I am not really sure what to do here, as I don't know how to apply a color to something that isn't WriteHost or WriteColor module.

Thanks!

harrymc
  • 455,459
  • 31
  • 526
  • 924
Giacomo
  • 25
  • 6
  • Possible duplicate of [How to colorize the Powershell prompt?](https://superuser.com/questions/1259900/how-to-colorize-the-powershell-prompt) – harrymc Mar 30 '19 at 10:06

1 Answers1

0

This is only possible by using Write-Host.

For example, this simple Prompt method sets the color of the prompt to yellow:

function Prompt
{
    $promptString = "PS " + $(Get-Location) + ">"
    Write-Host $promptString -NoNewline -ForegroundColor Yellow
    return " "
}
harrymc
  • 455,459
  • 31
  • 526
  • 924