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 ColorNameLet’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
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 BlackThis 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
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
}
Or for warnings:
Write-Host "WARNING: This operation will delete files." -ForegroundColor YellowInformational 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 CyanCheck 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
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 RedI 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
}
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 GreenThis 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 GreenThe `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:

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 ErrorMuch 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:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.