다음을 통해 공유


Tee-Object

Saves command output in a file or variable and also sends it down the pipeline.

구문

File (기본값)

Tee-Object
    [-FilePath] <String>
    [-InputObject <PSObject>]
    [-Append]
    [<CommonParameters>]

LiteralFile

Tee-Object
    -LiteralPath <String>
    [-InputObject <PSObject>]
    [<CommonParameters>]

Variable

Tee-Object
    -Variable <String>
    [-InputObject <PSObject>]
    [<CommonParameters>]

Description

The Tee-Object cmdlet redirects output, that is, it sends the output of a command in two directions (like the letter T). It stores the output in a file or variable and also sends it down the pipeline. If Tee-Object is the last command in the pipeline, the command output is displayed at the prompt.

예제

Example 1: Output processes to a file and to the console

This example gets a list of the processes running on the computer and sends the result to a file. Because a second path is not specified, the processes are also displayed in the console.

Get-Process | Tee-Object -FilePath "C:\Test1\testfile2.txt"
Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)    Id ProcessName
-------  ------    -----      ----- -----   ------    -- -----------
83       4     2300       4520    39     0.30    4032 00THotkey
272      6     1400       3944    34     0.06    3088 alg
81       3      804       3284    21     2.45     148 ApntEx
81       4     2008       5808    38     0.75    3684 Apoint
...

Example 2: Output processes to a variable and `Select-Object`

This example gets a list of the processes running on the computer, saves them to the $proc variable, and pipes them to Select-Object.

Get-Process notepad | Tee-Object -Variable proc | Select-Object ProcessName, Handles
ProcessName                              Handles
-----------                              -------
notepad                                  43
notepad                                  37
notepad                                  38
notepad                                  38

The Select-Object cmdlet selects the ProcessName and Handles properties. Note that the $proc variable includes the default information returned by Get-Process.

Example 3: Output system files to two log files

This example saves a list of system files in a two log files, a cumulative file and a current file.

Get-ChildItem -Path D: -File -System -Recurse |
  Tee-Object -FilePath "C:\test\AllSystemFiles.txt" -Append |
    Out-File C:\test\NewSystemFiles.txt

The command uses the Get-ChildItem cmdlet to do a recursive search for system files on the D: drive. A pipeline operator (|) sends the list to Tee-Object, which appends the list to the AllSystemFiles.txt file and passes the list down the pipeline to the Out-File cmdlet, which saves the list in the NewSystemFiles.txt file.

매개 변수

-Append

Indicates that the cmdlet appends the output to the specified file. Without this parameter, the new content replaces any existing content in the file without warning.

This parameter was introduced in Windows PowerShell 3.0.

매개 변수 속성

형식:SwitchParameter
Default value:False
와일드카드 지원:False
DontShow:False

매개 변수 집합

File
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-FilePath

Specifies a file that this cmdlet saves the object to Wildcard characters are permitted, but must resolve to a single file.

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:True
DontShow:False

매개 변수 집합

File
Position:0
필수:True
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-InputObject

Specifies the object to be saved and displayed. Enter a variable that contains the objects or type a command or expression that gets the objects. You can also pipe an object to Tee-Object.

When you use the InputObject parameter with Tee-Object, instead of piping command results to Tee-Object, the InputObject value is treated as a single object even if the value is a collection.

매개 변수 속성

형식:PSObject
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:True
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-LiteralPath

Specifies a file that this cmdlet saves the object to. Unlike FilePath, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False
별칭:PSPath

매개 변수 집합

LiteralFile
Position:Named
필수:True
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-Variable

Specifies a variable that the cmdlet saves the object to. Enter a variable name without the preceding dollar sign ($).

매개 변수 속성

형식:String
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

Variable
Position:Named
필수:True
파이프라인의 값: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 object that it redirects.

참고

Windows PowerShell includes the following aliases for Tee-Object:

  • tee

You can also use the Out-File cmdlet or the redirection operator, both of which save the output in a file but do not send it down the pipeline.

Tee-Object uses "Unicode" (UTF-16LE) encoding when it writes to files. If you need a different encoding, use the Out-File cmdlet with the Encoding parameter.