PowerShell provides the
Write-Output command in order to print objects, variables, and values to the console. It is very similar to the Linux
echo command. To make things easier the
echo an alias can be used instead of the Write-Output command to make Linux users comfortable. The Write-Output command can be used with the other commands by piping their outputs and printing them to the console. In this tutorial, we examine the usage of the Write-Output command.
The Write-Output command can be used to print variable values. These variables can be different types like an object, integer, etc.
PS> $Name="Ismail Baydan" PS> Write-Output $Name PS> $Age=38 PS> Write-Output $Age
Suppress Enumeration In Output
By default the Write-Output prints every object as different items. But we can provide the whole output as a single object by using the
PS> Write-Output 1,2,3 -NoEnumerate | Measure-Object PS> Write-Output 1,2,3 | Measure-Object
Print Redirected or Piped Inputs
We can redirect or pipe different commands output into the Write-Output command.
PS> Get-Process | Write-Output