Write-Output
Write-Output [-InputObject*] <PSObject[]> [-NoEnumerate] [<CommonParameters>]
The Write-Output cmdlet sends the specified object down the pipeline to the next command. If the command is the last command in the pipeline, the object is displayed in the console. Write-Output 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.
This cmdlet is typically used in scripts to display strings and other objects on the console. However, because the default behavior is to display the objects at the end of a pipeline, it is generally not necessary to use the cmdlet. For instance, `Get-Process | Write-Output` is equivalent to `Get-Process`.
Parameters
-InputObject <PSObject[]>
- This value is required
- Default value is None
- Accepts pipeline input ByValue
Specifies the objects to send down the pipeline. Enter a variable that contains the objects, or type a command or expression that gets the objects.
-NoEnumerate [<SwitchParameter>]
- Default value is False
- Accepts pipeline input False
By default, the Write-Output cmdlet always enumerates its output. The NoEnumerate parameter suppresses the default behavior, and prevents Write-Output from enumerating output. The NoEnumerate parameter has no effect on collections that were created by wrapping commands in parentheses, because the parentheses force enumeration.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.
Inputs
System.Management.Automation.PSObjectOutputs
System.Management.Automation.PSObjectExamples
-
Get objects and write them to the console:
PS C:\> $P = Get-Process PS C:\> Write-Output $P PS C:\> $P
The first command gets processes running on the computer and stores them in the $P variable.
The second and third commands display the process objects in $P on the console.
-
Pass output to another cmdlet:
PS C:\> Write-Output "test output" | Get-Member
This command pipes the "test output" string to the Get-Member cmdlet, which displays the members of the System.String class, demonstrating that the string was passed along the pipeline.
-
Suppress enumeration in output:
PS C:\> Write-Output @(1,2,3) | measure Count : 3 ... PS C:\> Write-Output @(1,2,3) -NoEnumerate | measure Count : 1
This command adds the NoEnumerate parameter to treat a collection or array as a single object through the pipeline.
Additional Notes
This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.
PowerShell Commands