Write-Output
generates output. This output can go to the next command after the pipeline or to the console so it's simply displayed.
The Cmdlet sends objects down the primary pipeline, also known as the "output stream" or the "success pipeline." To send error objects down the error pipeline, use Write-Error.
# 1.) Output to the next Cmdlet in the pipeline
Write-Output 'My text' | Out-File -FilePath "$env:TEMP\Test.txt"
Write-Output 'Bob' | ForEach-Object {
"My name is $_"
}
# 2.) Output to the console since Write-Output is the last command in the pipeline
Write-Output 'Hello world'
# 3.) 'Write-Output' CmdLet missing, but the output is still considered to be 'Write-Output'
'Hello world'
Because Write-Output
's default behavior is to display the objects at the end of a pipeline, it is generally not necessary to use the Cmdlet. For example, Get-Process | Write-Output
is equivalent to Get-Process
.