Write-Verbose vs Write-Host in PowerShell

Rohan Timalsina May 21, 2022
  1. Use Write-Verbose in PowerShell
  2. Use Write-Host in PowerShell
Write-Verbose vs Write-Host in PowerShell

Writing output to the console is a fundamental feature of any language as it provides information to the user. There are multiple cmdlets in PowerShell that produce output on the console.

Write-Verbose and Write-Host are one of them. This tutorial will teach you to use Write-Verbose and Write-Host cmdlet in PowerShell.

Use Write-Verbose in PowerShell

The Write-Verbose cmdlet writes text to the verbose message stream in PowerShell. The verbose message is not displayed in the output by default.

It will only be displayed by changing $VerbosePreference to True or using the -Verbose parameter in the command. The first command output is not printed, but the second command output is printed on the console.

Example:

Write-Verbose -Message "Loading files..."
Write-Verbose -Message "Loading files..." -Verbose

Output:

VERBOSE: Loading files...

Use Write-Host in PowerShell

The Write-Host cmdlet is used to write outputs to a host. It displays output to the console.

Example:

Write-Host "Learn PowerShell"

Output:

Learn PowerShell

You can specify the text color using the -ForegroundColor parameter, whereas the background color can be set by using the -BackgroundColor parameter.

Write-Host "Learn PowerShell" -ForegroundColor Red -BackgroundColor White
Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website

Related Article - PowerShell Command