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