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!

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 " "
}
  • Thanks so much, works great! Appreciate it :D – Giacomo Mar 30 '19 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.