The Echo Equivalent in PowerShell

Rohan Timalsina Dec 10, 2021
  1. Use Write-Output as echo Equivalent in PowerShell
  2. Use Write-Host as echo Equivalent in PowerShell
  3. Use Write-Debug as Echo Equivalent in PowerShell
  4. Use Write-Verbose as Echo Equivalent in PowerShell
The Echo Equivalent in PowerShell

The echo command prints the strings or variables on the console. This tutorial will introduce different commands equivalent to the echo in PowerShell scripts and functions.

echo "Hello World."

Output:

Hello World.

Use Write-Output as echo Equivalent in PowerShell

The closest echo equivalent is Write-Output. echo is the built-in alias for Write-Output. The Write-Output writes output data to the pipeline and allows you to redirect the output to another command or file. The output data is displayed on the PowerShell console if piping is not done.

Write-Output "Hello World."

Output:

Hello World.

Use Write-Host as echo Equivalent in PowerShell

The Write-Host cmdlet in PowerShell is used to write the output directly to the PowerShell console. You can also customize the font color and background color using -ForegroundColor and -BackgroundColor parameter.

Write-Host "Hello World."

Output:

Hello World.

Use Write-Debug as Echo Equivalent in PowerShell

The Write-Debug cmdlet writes a debug message directly to the PowerShell console if $DebugPreference is set to Continue or Stop. The default value of $DebugPreference is SilentlyContinue.

$DebugPreference = Continue
Write-Debug "Hello World."

Output:

DEBUG: Hello World.

Use Write-Verbose as Echo Equivalent in PowerShell

The Write-Verbose cmdlet writes a verbose message directly to the PowerShell console if $VerbosePreference is set to Continue or Stop.

$VerbosePreference = Continue
Write-Verbose "Hello World."

Output:

DEBUG: Hello World.
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