Write-Output

suggest change

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'
  1. The Write-Output cmdlet sends the specified object down the pipeline to the next command.
  2. If the command is the last command in the pipeline, the object is displayed in the console.
  3. The PowerShell interpreter treats this as an implicit Write-Output.

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents