Tee-Object
Applies To: Windows PowerShell 2.0
Saves command output in a file or variable, and displays it in the console.
Tee-Object [-FilePath] <string> [-InputObject <psobject>] [<CommonParameters>]
Tee-Object -Variable <string> [-InputObject <psobject>] [<CommonParameters>]
The Tee-Object cmdlet 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 in the console.
Specifies the file where the cmdlet stores the object. Accepts wildcards that resolve to a single file.
Required? |
true |
Position? |
1 |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
Specifies the object input to the cmdlet. Enter a variable that contains the objects or type a command or expression that gets the objects.
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
true (ByValue) |
Accept Wildcard Characters? |
false |
Assigns a reference to the input objects to the specified variable.
Required? |
true |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
This command supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, OutBuffer, OutVariable, WarningAction, and WarningVariable. For more information, see about_CommonParameters.
The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet returns.
Inputs |
System.Management.Automation.PSObject You can pipe objects to be redirected to Tee-Object. |
Outputs |
System.Management.Automation.PSObject Tee-Object returns the object that it redirected. |
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 encoding when it writes to files. As a result, the output might not be formatted properly in files with a different encoding. To specify the encoding, use the Out-File cmdlet.
C:\PS>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
...
Description
-----------
This command 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 result will be displayed in the console.
C:\PS>get-process notepad | tee-object -variable proc | select-object processname,handles
ProcessName Handles
----------- -------
notepad 43
notepad 37
notepad 38
notepad 38
Description
-----------
This command gets a list of the processes running on the computer and sends the result to a variable named "proc". It then pipes the resulting objects along to Select-Object, which selects the ProcessName and Handles property. Note that the $proc variable includes the default information returned by Get-Process.