Tee-Object
Published: February 29, 2012
Updated: August 15, 2012
Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0
Tee-Object
Aliases
The following abbreviations are aliases for this cmdlet:
- tee
Syntax
Parameter Set: File Tee-Object [-FilePath] <String> [-Append] [-InputObject <PSObject> ] [ <CommonParameters>] Parameter Set: LiteralFile Tee-Object -LiteralPath <String> [-InputObject <PSObject> ] [ <CommonParameters>] Parameter Set: Variable Tee-Object -Variable <String> [-InputObject <PSObject> ] [ <CommonParameters>]
Detailed 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.
Parameters
-Append
Appends the output to the specified file. Without this parameter, the new content replaces any existing content in the file without warning.
This parameter is introduced in Windows PowerShell 3.0.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
Replace |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-FilePath<String>
Saves the object in the specified file. Wildcard characters are permitted, but must resolve to a single file.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
1 |
|
Default Value |
None |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
true |
-InputObject<PSObject>
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.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
none |
|
Accept Pipeline Input? |
true (ByValue) |
|
Accept Wildcard Characters? |
false |
-Variable<String>
Saves the object in the specified variable. Enter a variable name without the preceding dollar sign ($).
|
Aliases |
none |
|
Required? |
true |
|
Position? |
named |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-LiteralPath<String>
Saves the object in the specified file. 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 Windows PowerShell not to interpret any characters as escape sequences.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
named |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
-
System.Management.Automation.PSObject
You can pipe objects to Tee-Object.
Outputs
The output type is the type of the objects that the cmdlet emits.
-
System.Management.Automation.PSObject
Tee-Object returns the object that it redirects.
Notes
-
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.
Examples
-------------------------- EXAMPLE 1 --------------------------
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 processes are also displayed in the console.
PS C:\> get-process | tee-object -filepath C:\Test1\testfile2.txtHandles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName------- ------ ----- ----- ----- ------ -- -----------83 4 2300 4520 39 0.30 4032 00THotkey272 6 1400 3944 34 0.06 3088 alg81 3 804 3284 21 2.45 148 ApntEx81 4 2008 5808 38 0.75 3684 Apoint...
-------------------------- EXAMPLE 2 --------------------------
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.
PS C:\> get-process notepad | tee-object -variable proc | select-object processname,handlesProcessName Handles----------- -------notepad 43notepad 37notepad 38notepad 38
-------------------------- EXAMPLE 3 --------------------------
This command saves a list of system files in a two log files, a cumulative file and a current file.
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.
PS C:\> get-childitem –path D: –file –system –recurse | tee-object –file c:\test\AllSystemFiles.txt –append | out-file c:\test\NewSystemFiles.txt
Related topics