# A Prompt in Your Colors

PowerShell's prompt is a function named prompt that runs before every command you type, so you can write your own that shows the folder's name, the time and colors from $PSStyle, and keep it in your profile.

Journeyman · PowerShell · Updated November 10, 2026

## After this lesson you can

- Write a prompt function that shows the folder's name, the time or other text you choose
- Color parts of the prompt with $PSStyle, ending with $PSStyle.Reset, and keep the prompt in your profile

## Key takeaways

- The prompt is a function named `prompt`. PowerShell runs it before every command and prints the text it gives back.
- Write your own with `function prompt { … }`: `Split-Path -Leaf (Get-Location)` is the folder's name, and `Get-Date -Format 'HH:mm'` the time.
- `$PSStyle.Foreground.Cyan` and its friends switch on a color, and `$PSStyle.Reset` switches it off again. Forget the reset and your typing turns cyan too.
- Put your prompt function in your profile to keep it.

Your photo project is five folders deep, and the prompt now reads `PS C:\Users\Sam\terminal-practice\photos\2026\summer\day-3-lake>` before you've typed a thing. Half the line is gone, and with three tabs open you can't tell which is which at a glance. The prompt is yours to change: shorter, with the time, in colors you like. It's a small thing that makes PowerShell feel like your own.

This lesson works in a deep practice folder. Make it and go there:

```powershell
New-Item -ItemType Directory -Force -Path "$HOME\terminal-practice\photos\2026\summer\day-3-lake" | Out-Null
Set-Location "$HOME\terminal-practice\photos\2026\summer\day-3-lake"
```

They print nothing when they work.

## The prompt is a function

The **prompt**, the text before the cursor, isn't fixed: PowerShell runs a function named `prompt` before every command and prints whatever text it gives back. You can call it yourself:

```powershell
prompt
```

```text
PS C:\Users\Sam\terminal-practice\photos\2026\summer\day-3-lake>
```

Write a function with the same name, and yours replaces it. *Aliases and Small Functions* showed how; a prompt function ends with the text to show.

## Your own prompt

This one shows only the folder you're in. `Split-Path -Leaf` splits a path and keeps the leaf, its last part, as a tree's branches end in leaves:

```powershell
function prompt {
    "$(Split-Path -Leaf (Get-Location))> "
}
```

```text
day-3-lake>
```

The next line PowerShell shows is already the new prompt. The `$( )` inside the double quotes runs a command and puts its answer into the text, as in *Text: Quotes and $( )*. Add the time with `Get-Date -Format 'HH:mm'`, the hour and minute on a 24-hour clock:

```powershell
function prompt {
    "[$(Get-Date -Format 'HH:mm')] $(Split-Path -Leaf (Get-Location))> "
}
```

```text
[06:16] day-3-lake>
```

Your time will be the time you run it; it updates with every new prompt, which tells you when the last command finished.

## Colors: $PSStyle

Terminals understand hidden instructions inside text, such as "from here on, cyan". They're called **ANSI escape codes**, and `$PSStyle` gives them names, so you never type the codes. It has a color for each of these names:

```powershell
$PSStyle.Foreground | Get-Member -MemberType Property | Select-Object -ExpandProperty Name
```

```text
Black
Blue
BrightBlack
BrightBlue
BrightCyan
BrightGreen
BrightMagenta
BrightRed
BrightWhite
BrightYellow
Cyan
Green
Magenta
Red
White
Yellow
```

`$PSStyle.Bold` makes text bold, and `$PSStyle.Reset` puts everything back to normal. Put a color in front of the part you want colored, and the reset after it:

```powershell
function prompt {
    $time = Get-Date -Format 'HH:mm'
    $folder = Split-Path -Leaf (Get-Location)
    "$($PSStyle.Foreground.BrightBlack)[$time]$($PSStyle.Reset) $($PSStyle.Bold)$($PSStyle.Foreground.Cyan)$folder$($PSStyle.Reset)> "
}
```

```text
[06:16] day-3-lake>
```

On your screen, the time is gray and the folder's name bold cyan:

![Windows Terminal with the new prompt: the time 06:16 in gray in square brackets, then day-3-lake in bold cyan, then a white > and the cursor](https://www.ask-codey.com/lessons/TODO)

**Forget the reset, and the color keeps going**: everything you type after the prompt turns cyan too. And the function must give back text. One that only uses `Write-Host` prints its words but gives back nothing, and PowerShell adds a plain `PS>` of its own.

## Keep it

A prompt you set at the prompt lasts until the window closes. When you like it, copy the function into your profile (`edit $PROFILE`, after keeping a copy) and load it with `. $PROFILE`, as *Your Profile* shows.

Windows PowerShell 5.1 has no `$PSStyle`: there, write the colored part with `Write-Host "[$time]" -ForegroundColor DarkGray -NoNewline`, and still end the function with the text to give back. On a Mac or Linux, everything here works the same.

**Want more?** Oh My Posh is a free program that draws ready-made prompt themes, with the Git branch, icons and more. It's installed with winget, from *Installing Apps and Modules: winget and the PowerShell Gallery*, and turned on with one line in your profile; its icons need a special font, and its website, ohmyposh.dev, walks you through it. It's an optional extra: the prompt you wrote yourself is all you need.

## Check yourself

2 questions to try on the lesson page.

## So what

The prompt is the line you look at more than any other, and now it shows what you want, in your colors.

## Key terms

- [Prompt](https://www.ask-codey.com/glossary/prompt-operating-system)
- [$PSStyle](https://www.ask-codey.com/glossary/psstyle)
- [ANSI Escape Code](https://www.ask-codey.com/glossary/ansi-escape-code)

## Cheat sheets

- [A Prompt in Your Colors](https://www.ask-codey.com/cheat-sheets/powershell-custom-prompt-cheat-sheet)

## Related

- [Your Profile](https://www.ask-codey.com/lessons/powershell-profile)
- [Aliases and Small Functions](https://www.ask-codey.com/lessons/powershell-aliases-and-small-functions)

Source: https://www.ask-codey.com/lessons/powershell-custom-prompt
