PowerShell Write-Host Color [With Examples]

You know what’s annoying? Staring at a PowerShell window filled with endless lines of white text on a blue background, trying to figure out which messages are errors, which are warnings, and which are just informational notes.

I’ve been there. Running a script and missing a critical warning because everything looks the same. Or worse, showing a script demo to your team and watching their eyes glaze over because the output looks like alphabet soup.

That’s where Write-Host with colors comes in. It’s one of those simple PowerShell features that makes a huge difference in how readable and professional your scripts look. And the best part? It’s dead simple to use.

Let me walk you through everything you need to know about using colors in the PowerShell Write-Host cmdlet.

What is Write-Host and Why Should You Care?

Write-Host is a PowerShell cmdlet that displays text in the console. Think of it as PowerShell’s way of saying “Hey, look at this!”

Now, some PowerShell purists will tell you to avoid Write-Host because it only displays text and doesn’t pass objects down the pipeline. They’re not wrong, but here’s the thing: when you want to show messages to users running your scripts, Write-Host is perfect.

And when you add colors to it? Even better.

Here’s a simple example:

Write-Host "This is a message"

That’s it. You just displayed text. Now let’s make it useful.

The Basic Syntax of Write-Host with Colors

The basic structure looks like this:

Write-Host "Your message here" -ForegroundColor ColorName -BackgroundColor ColorName

Let’s break this down:

  • “Your message here” – The text you want to display
  • -ForegroundColor – Changes the text color
  • -BackgroundColor – Changes the background color behind the text

You can use one or both color parameters. Most of the time, I just use ForegroundColor because it’s cleaner.

Here’s a real example:

Write-Host "Success! The file was created." -ForegroundColor Green
PowerShell Write-Host Color

See? Not complicated at all.

Check out PowerShell Write-Host to File

All the Colors You Can Use

PowerShell gives you 16 colors to work with. Here’s the complete list:

  • Black
  • DarkBlue
  • DarkGreen
  • DarkCyan
  • DarkRed
  • DarkMagenta
  • DarkYellow
  • Gray
  • DarkGray
  • Blue
  • Green
  • Cyan
  • Red
  • Magenta
  • Yellow
  • White

Want to see them all in action? Run this quick script:

Write-Host "Black" -ForegroundColor Black -BackgroundColor White
Write-Host "DarkBlue" -ForegroundColor DarkBlue
Write-Host "DarkGreen" -ForegroundColor DarkGreen
Write-Host "DarkCyan" -ForegroundColor DarkCyan
Write-Host "DarkRed" -ForegroundColor DarkRed
Write-Host "DarkMagenta" -ForegroundColor DarkMagenta
Write-Host "DarkYellow" -ForegroundColor DarkYellow
Write-Host "Gray" -ForegroundColor Gray
Write-Host "DarkGray" -ForegroundColor DarkGray
Write-Host "Blue" -ForegroundColor Blue
Write-Host "Green" -ForegroundColor Green
Write-Host "Cyan" -ForegroundColor Cyan
Write-Host "Red" -ForegroundColor Red
Write-Host "Magenta" -ForegroundColor Magenta
Write-Host "Yellow" -ForegroundColor Yellow
Write-Host "White" -ForegroundColor White -BackgroundColor Black

This gives you a nice color palette to reference whenever you’re writing scripts.

Check out PowerShell Write-Host vs Write-Information

Practical Ways to Use Colors in Your Scripts

Okay, so you know the colors. But how do you actually use them in real scripts? Let me show you some patterns I use all the time.

Success Messages in Green

Whenever something works correctly, show it in green:

Copy-Item "C:\Source\file.txt" "C:\Destination\file.txt"
Write-Host "File copied successfully!" -ForegroundColor Green
powershell write host different colours

Green = good. Simple psychology that everyone understands.

Errors and Warnings in Red or Yellow

When things go wrong, use red. For warnings that aren’t critical, use yellow:

if (Test-Path "C:\ImportantFile.txt") {
    Write-Host "File found. Proceeding..." -ForegroundColor Green
} else {
    Write-Host "ERROR: File not found!" -ForegroundColor Red
}
powershell write-host color examples

Or for warnings:

Write-Host "WARNING: This operation will delete files." -ForegroundColor Yellow

Informational Messages in Cyan or White

For general information that’s not good or bad, I like cyan or white:

Write-Host "Starting backup process..." -ForegroundColor Cyan
Write-Host "Connecting to server..." -ForegroundColor Cyan
Write-Host "Scanning directories..." -ForegroundColor Cyan

Check out PowerShell Write-Host vs Write-Output

Creating Section Headers

When your script has multiple parts, use colors to create visual sections:

Write-Host "`n========== STEP 1: VALIDATION ==========" -ForegroundColor Magenta
# validation code here

Write-Host "`n========== STEP 2: PROCESSING ==========" -ForegroundColor Magenta
# processing code here

Write-Host "`n========== STEP 3: CLEANUP ==========" -ForegroundColor Magenta
# cleanup code here
powershell write host list

The `n at the start adds a blank line before each header. Makes things more readable.

Check out PowerShell Write-Host vs Write-Error

Combining Foreground and Background Colors

You can use both foreground and background colors together for extra emphasis:

Write-Host "CRITICAL ERROR!" -ForegroundColor White -BackgroundColor Red

I don’t use background colors much because they can be hard to read. But for critical alerts, they really grab attention.

Here’s a practical example:

$diskSpace = Get-PSDrive C | Select-Object -ExpandProperty Free
$diskSpaceGB = [math]::Round($diskSpace / 1GB, 2)

if ($diskSpaceGB -lt 10) {
    Write-Host "WARNING: Only $diskSpaceGB GB free!" -ForegroundColor Black -BackgroundColor Yellow
} elseif ($diskSpaceGB -lt 5) {
    Write-Host "CRITICAL: Only $diskSpaceGB GB free!" -ForegroundColor White -BackgroundColor Red
} else {
    Write-Host "Disk space OK: $diskSpaceGB GB free" -ForegroundColor Green
}
write-host variable powershell

Using NoNewline for Same-Line Updates

Here’s a cool trick. The -NoNewline parameter keeps the cursor on the same line:

Write-Host "Processing file 1..." -NoNewline -ForegroundColor Cyan
Start-Sleep -Seconds 2
Write-Host " Done!" -ForegroundColor Green

This creates a nice effect where “Done!” appears on the same line as the message.

You can use this for progress indicators:

$files = Get-ChildItem "C:\Data" -File
$total = $files.Count
$current = 0

foreach ($file in $files) {
    $current++
    Write-Host "`rProcessing file $current of $total..." -NoNewline -ForegroundColor Yellow
    # process file here
}
Write-Host "`rAll files processed!                    " -ForegroundColor Green

The `r is a carriage return that moves the cursor back to the start of the line.

Creating a Color-Coded Log Function

Want to level up? Create a reusable function for color-coded messages:

function Write-Log {
    param(
        [string]$Message,
        [string]$Type = "Info"
    )

    switch ($Type) {
        "Success" { Write-Host "[SUCCESS] $Message" -ForegroundColor Green }
        "Error"   { Write-Host "[ERROR]   $Message" -ForegroundColor Red }
        "Warning" { Write-Host "[WARNING] $Message" -ForegroundColor Yellow }
        "Info"    { Write-Host "[INFO]    $Message" -ForegroundColor Cyan }
        default   { Write-Host $Message -ForegroundColor White }
    }
}

# ---- Example Usage ----
Write-Log "Script started" "Info"
Write-Log "Connected to server successfully" "Success"
Write-Log "Disk space is running low" "Warning"
Write-Log "Failed to retrieve data" "Error"
Write-Log "This is a default message"

Now you can use it throughout your scripts:

powershell write-host without newline
Write-Log "Starting process..." -Type Info
Write-Log "Connection successful!" -Type Success
Write-Log "Low memory detected" -Type Warning
Write-Log "Failed to connect" -Type Error

Much cleaner, right?

Check out PowerShell Write-Host vs Echo

Common Mistakes to Avoid

Let me save you some headaches by sharing mistakes I’ve made:

  • Don’t use too many colors. Your script will look like a rainbow threw up. Stick to 3-4 colors with clear meanings.
  • Avoid low-contrast combinations. Yellow text on white background? Unreadable. DarkBlue on black? Same problem.
  • Remember that Write-Host doesn’t write to the pipeline. If you need to capture output, use Write-Output instead.
  • Don’t rely only on color. Some users might have color blindness or use screen readers. Include text cues like “ERROR:” or “SUCCESS:” in your messages.

Testing Your Color Schemes

Different PowerShell consoles can display colors differently. Windows PowerShell, PowerShell 7, VS Code terminal, and Windows Terminal all have slightly different color rendering.

Always test your scripts in the environment where they’ll actually run. What looks great in VS Code might look terrible in the standard PowerShell console.

When NOT to Use Write-Host

Quick reality check: Write-Host isn’t always the answer.

Don’t use it when:

  • You’re writing functions that other scripts will call
  • You need to capture or redirect output
  • You’re creating tools for automation (where humans won’t see the output)

In those cases, use Write-Output, Write-Verbose, Write-Warning, or Write-Error instead. These cmdlets work with PowerShell’s streams and can be captured, redirected, or suppressed as needed.

But for user-facing scripts where you want clear, visual feedback? Write-Host with colors is your friend.

Wrapping Up

Adding colors to your PowerShell scripts isn’t just about making them pretty. It’s about communication. Green says, “Everything’s fine.” Red says, “Pay attention, something’s wrong.” Yellow says, “heads up, but don’t panic.”

Start simple. Add green for successes and red for errors. That alone will make your scripts way more user-friendly.

Then experiment with the other colors. Create headers, status messages, and progress indicators. Before you know it, you’ll be writing scripts that are not just functional, but actually pleasant to watch run.

I hope you now understand everything about PowerShell Write-Host Color.

Also, you may like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.