PowerShell Genie

Write-Output

Use Write-Output to send objects to the success stream, which is the stream the pipeline carries and a caller can capture.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Write-Output

Syntax

1PS> Write-Output [-InputObject] <PSObject[]> [-NoEnumerate] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Write-Output [-InputObject] <PSObject[]> [-NoEnumerate] [<CommonParameters>]
  1. Stage 1Write-Output-InputObject -NoEnumerate

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Write with Write-Output

    1PS> $msg = Write-Output 'captured'
    2PS> $msg
    Show reference output

    Sample output · fictional data, shaped like the real thing

    captured

    Select Count

    1PS> Write-Output (1 , 2 , 3) -NoEnumerate | Measure-Object | Select-Object Count
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Count
    -----
        1

    Parameters

    Parameter definitions:

    • -InputObject
    • -NoEnumerate

    Write-Output on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Write-Output when you need to send objects to the success stream, which is the stream the pipeline carries and a caller can capture. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A function returning diagnostic text alongside objects can break callers. Keep only the intended result objects on the success stream and move narration to a diagnostic stream. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Out-Host. Out-Host sends output to the host display; Write-Output sends it along the success pipeline. Sending a result to the host prevents ordinary downstream object processing. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Write-Output reference on Microsoft Learn

    Put this command to work

    Catch a missing service

    Request MissingService with -ErrorAction Stop inside try/catch. Return Service unavailable from the catch block.

    Review the lesson

    Recap

    Write-Output Use Write-Output to send objects to the success stream, which is the stream the pipeline carries and a caller can capture.

    Next: Write-Information
    Genie guideWrite-Output

    Use Write-Output to send objects to the success stream, which is the stream the pipeline carries and a caller can capture. The console below is pre-loaded — run it, then change a value and run it again.