Write-Output
Writes the specified objects to the pipeline.
구문
Default (기본값)
Write-Output
[-InputObject] <PSObject[]>
[-NoEnumerate]
[<CommonParameters>]
Description
Writes the specified objects to the pipeline. If Write-Output
is the last command in the pipeline,
the objects are displayed in the console.
Write-Output
sends objects to the primary pipeline, also known as the success stream. To send
error objects to the error stream, use Write-Error
.
This cmdlet is typically used in scripts to display strings and other objects on the console. One of
the built-in aliases for Write-Output
is echo
and similar to other shells that use echo
. The
default behavior is to display the output at the end of a pipeline. In PowerShell, it is generally
not necessary to use the cmdlet in instances where the output is displayed by default. For example,
Get-Process | Write-Output
is equivalent to Get-Process
. Or, echo "Home directory: $HOME"
can
be written, "Home directory: $HOME"
.
By default, Write-Output
enumerates objects in a collection. However, Write-Output
can also
pass collections down the pipeline as a single object with the NoEnumerate parameter.
예제
Example 1: Get objects and write them to the console
In this example, the results of the Get-Process
cmdlet are stored in the $P
variable. The
Write-Output
cmdlet displays the process objects in $P
to the console.
$P = Get-Process
Write-Output $P
Example 2: Pass output to another cmdlet
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.
Write-Output "test output" | Get-Member
Example 3: Suppress enumeration in output
This command adds the NoEnumerate parameter to treat a collection or array as a single object through the pipeline.
Write-Output 1,2,3 | Measure-Object
Count : 3
...
Write-Output 1,2,3 -NoEnumerate | Measure-Object
Count : 1
...
매개 변수
-InputObject
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.
매개 변수 속성
형식: | PSObject[] |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
(All)
Position: | 0 |
필수: | True |
파이프라인의 값: | True |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
-NoEnumerate
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 if the command is wrapped in parentheses, because the
parentheses force enumeration. For example, (Write-Output 1,2,3 -NoEnumerate)
still enumerates
the array.
The NoEnumerate parameter is only useful within a pipeline. Trying to see the effects of
NoEnumerate in the console is problematic because PowerShell adds Out-Default
to the end of
every command line, which results in enumeration. But if you pipe Write-Output -NoEnumerate
to
another cmdlet, the downstream cmdlet receives the collection object, not the enumerated items of
the collection.
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
입력
PSObject
You can pipe objects to this cmdlet.
출력
PSObject
This cmdlet returns the objects that are submitted as input.
참고
PowerShell includes the following aliases for Write-Output
:
All platforms:
echo
Windows:
write