Write Output - PowerShell
Overview
Write-Output is a fundamental command in PowerShell that allows users to output text or objects to the console or a file. It is used for printing messages, debugging information, and displaying results in a clear and organized manner.
Syntax
Write-Output [-InputObject] <object[]>
Parameters
| Parameter | Description |
|—|—|
| -InputObject | Specifies the objects to output. If not specified, the current pipeline object is used. |
Options/Flags
None.
Examples
Simple Output
Write-Output "Hello, world!"
Outputting Multiple Objects
Write-Output 1, 2, 3, "Hello", "World"
Outputting Formatted Objects
$person = New-Object -TypeName PSObject -Property @{
Name = "John Doe"
Age = 30
}
Write-Output $person
Common Issues
Output Truncation
By default, Write-Output truncates long lines to 1024 characters. To disable this, use $MaximumLineLength = Unlimited
.
Excessive Output
If the pipeline produces too much output, use Out-Null
to suppress it:
Get-Process | Out-Null
Integration
Write-Output can be used with other commands to create complex output formats:
Get-Service | Format-List -Property Name, Status | Write-Output
Related Commands
- Write-Host: Outputs text directly to the console without line breaks.
- Format-Table: Outputs objects in a tabular format.
- ConvertTo-Html: Outputs objects as HTML.