The Write-Host cmdlet is used to display text directly in the PowerShell host, primarily for interactive scripts and messages intended for the user. It is commonly used to display status messages, prompts, warnings, or other info where customized console formatting is useful.
When you are debugging and diagnostic messages, you can use Write-Debug or Write-Verbose instead. These cmdlets can be enabled/suppressed using common PowerShell parameters and preference variables. This makes them more suitable for scripts that need configurable diagnostic output.
Unlike Write-Output, Write-Host does not write objects to the success output stream. Since PowerShell 5.0, however, Write-Host writes its messages to the Information stream.
Using Write-Host Output
To output a simple string to the PowerShell console, run the following command:
Write-Host "Script Started"

A new line with text will be output by this command. The color of the text is determined by the current PowerShell host and terminal color settings.
Unlike standard PowerShell output, the Write-Host command doesnโt trim lines in the output to match the width of the parent console window.
Using Write-Information for Capturable Messages
Starting with Windows PowerShell 5.0, Write-Host writes to the Information stream. However, if info messages may need to be captured, redirected, or suppressed, we recommend using the Write-Information cmdlet instead:
Write-Information "Deployment completed."
Capturing Write-Host output
Since PowerShell 5.0, Write-Host writes its messages to the Information stream (stream 6). This means that existing Write-Host output can still be captured/redirected without changing the script. For example, you should use 6>&1 to redirect the Information stream to the success output stream:
Write-Host "Deployment completed." 6>&1
You can then capture or redirect the output:
$output = Write-Host "Deployment completed." 6>&1
or:
Write-Host "Deployment completed." 6>&1 | Out-File .\output.txt
If you are writing new code and need messages to be programmatically consumed, filtered, redirected, or handled as inforecords, Write-Information is generally a better choice.
Note. Write-Host does not follow $InformationPreference in the same way as Write-Information. However, you can use -InformationAction Ignore to suppress Write-Host output:
Write-Host "This message is hidden" -InformationAction Ignore
Changing color and background of Write-Host cmdlet output
The Write-Host cmdlet lets you customize text output by changing its color and background. To attract the user’s attention, you can change the text or background color displayed using the options:
- -ForegroundColor
- -BackgroundColor
There are 16 different colors to choose from: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White.
For example:
Write-Host "Red text on a yellow background" -ForegroundColor Red -BackgroundColor Yellow

Using ANSI Colors in PowerShell 7
Keep in mind that PowerShell 7.2+ also supports ANSI text formatting through the $PSStyle automatic variable, which provides more flexible console formatting across supported terminals. Here is an example:
"$($PSStyle.Foreground.Green)Success$($PSStyle.Reset)"
Color formatting for informational messages in PowerShell scripts
In PowerShell scripts, it is a good practice to use color formatting for informational messages to help users understand what is happening and when actions may need to be taken.
For example, you can display a green message if an action is completed successfully. Errors can be displayed in red and warnings in yellow.
Write-Host "The task was successfully completed." -ForegroundColor Green Write-Host "Unable to connect to the SQL DB." -ForegroundColor Red Write-Host "No user accounts found." -ForegroundColor Yellow

Add the -NoNewline parameter to prevent the next output string line from automatically starting on a new line:
Write-Host "Current user name is " -ForegroundColor DarkYellow -NoNewline Write-Host "$env:USERNAME" -ForegroundColor Red -BackgroundColor White

It only makes sense to use Write-Host in PowerShell interactive scripts that involve user interaction through the console. It is usually used with the Read-Host cmdlet to prompt the user for input.
Because Write-Host writes directly to the host UI, its output is generally not suitable for logging, remoting, background jobs, or scheduled tasks.
Create pseudo-graphical menus in PowerShell scripts with Write-Host and Read-Host
The Write-Host and Read-Host commands are often used together to create pseudo-graphical menus in PowerShell scripts. For example:
# Show a colorful menu
Write-Host "=== SIMPLE MENU ===" -ForegroundColor Black -BackgroundColor White
Write-Host "1) Option One" -ForegroundColor Yellow
Write-Host "2) Option Two" -ForegroundColor Green
Write-Host "3) Exit" -ForegroundColor Red
# Ask the user to make a choice
$choice = Read-Host "Select an option (1-3)"
# Processing input
switch ($choice) {
"1" { Write-Host "You chose Option One." -ForegroundColor Yellow }
"2" { Write-Host "You chose Option Two." -ForegroundColor Green }
"3" { Write-Host "Exiting..." -ForegroundColor Red; exit }
default { Write-Host "Invalid choice, try again." -ForegroundColor Red }
}

Note. To run PS1 files, check the PowerShell script execution policy settings.
What is the purpose of the Write-Host cmdlet in PowerShell?
Write-Host displays text directly in the PowerShell console. It is commonly used to show status messages, progress updates, debugging information, prompts, and colorized output for interactive scripts.
How is Write-Host different from Write-Output?
Write-Host writes directly to the host UI and does not send objects to the PowerShell pipeline. In contrast, Write-Output writes objects to the pipeline so they can be captured, redirected, or processed by other commands.
Does Write-Host send output to the PowerShell pipeline?
No. Output produced by Write-Host is displayed only in the console and is generally unavailable for further pipeline processing.
Can Write-Host output be captured or redirected?
Starting with Windows PowerShell 5.0, Write-Host writes to the Information stream. However, if messages need to be captured, redirected, or suppressed, Microsoft recommends using Write-Information instead.
When should I avoid using Write-Host?
Avoid relying on Write-Host for scripts that need to support logging, remoting, background jobs, scheduled tasks, or pipeline processing, since its output is intended primarily for the console interface.
