Home » PowerShell » PowerShell echo equivalent command – Write-Output

PowerShell echo equivalent command – Write-Output

PowerShell echo alias command is Write-Output. The echo command is used to print strings or variables on the console.

You can use the PowerShell echo command as given:

echo "Echo Equivalent in PowerShell!"

The output of the above echo command in PowerShell is:

PowerShell echo command
PowerShell echo command

echo command prints the string or text passed as on argument.

You can use other PowerShell cmdlets like Write-Output, Write-Host, Write-Verbose, and Write-Debug for echo in PowerShell.

In this article, we will discuss using the PowerShell echo command and its equivalent echo alias in PowerShell.

Let’s practice!

Using PowerShell echo command

Syntax to use PowerShell echo is:

echo [argument]

For example,

echo "Everything you should know about PowerShell echo"

echo in PowerShell prints string or text written inside the double-quotes.

Cool Tip: How to concatenate string in PowerShell!

Using PowerShell echo variable

You can print the variable content using echo.

For example,

$strMsg = "Ultimate guide to PowerShell echo variable!"

echo "$strMsg" 

In the above example of PowerShell echo variable print,$strMsg contains the value of string data type.

Using echo variable inside the double quotes, it prints variable value on the console.

The output of the above command is:

PowerShell echo variable
PowerShell echo variable

Cool Tip: If you use a variable inside a single quote, it prints a variable name. Hence always use double-quotes.

Let’s practice the PowerShell echo equivalent command!

Cool Tip: How to exit script in PowerShell!

Using Write-Output as PowerShell echo equivalent

PowerShell Write-Output cmdlet is an alias or PowerShell echo equivalent command. It writes the output of the content to the console.

Syntax to use Write-Output command

Write-Output [-InputObject] [-NoEnumerate] []
PowerShell echo equivalent Write-Output
PowerShell echo equivalent Write-Output

Let’s practice with an example.

Write-Output "PowerShell echo equivalent command is Write-Output!"

The output of the above command is

PowerShell echo equivalent command is Write-Output!

Cool Tip: How to remove a user from the group in PowerShell!

Using Write-Host to print the content

Write-Host command in PowerShell is used to print the content to the PowerShell console.

You can use customization in Write-Host like applying foreground color, background color, font color for the parameter in the command.

Write-Host "PowerShell echo equivalent command : Write-Host" -ForegroundColor green -BackgroundColor black

In the above example,

The Write-Host command applies customization like foreground color and background color to parameters and prints it on the PowerShell console.

Write-Host PowerShell echo equivalent
Write-Host PowerShell echo equivalent

Cool Tip: How to use $null in PowerShell!

Use of PowerShell echo command in Function

You can use PowerShell echo or Write-Output in function to print the contents of a variable.

Let’s practice with an example.

Create a function to check number is even or odd. If the number is even, print the message to the console using Write-Output.

If the number is odd, use PowerShell echo to print the message.

Function CheckNumberIsEven($num) {

    if($num % 2 -eq 0) {
        Write-Output "$num is even"
        }
     else{
        echo "$num is odd"
     }

}

CheckNumberIsEven(4)

PowerShell echo and Write-Output command in PowerShell will print the value to the PowerShell console.

Cool Tip: How to Keep PowerShell Console Open using PowerShell NoExit switch!

Conclusion

I hope the above article about PowerShell echo and its equivalent Write-Output is helpful to you.

PowerShell echo print the argument passed to it on the console.

You can also print variable content using the PowerShell echo variable.

Write-Output is an alias for PowerShell echo to write the output message to the PowerShell console.

Cool Tip: Using Active Directory UserAccountControl flags in PowerShell!

Write-Host is also used to write the output message to the PowerShell console.

It provides customization for output messages like you can change font color, foreground color, or background color.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment