CmdID / PowerShell / Cmdlets / Tee
Tee-Object
Saves command output in a file or variable and also sends it down the pipeline. PowerShell reference
From the PowerShell reference
5 parameters
Alias tee
What it does
Saves command output in a file or variable and also sends it down the pipeline. The Tee-Object cmdlet write output in two directions. 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. Internally, Tee-Object uses the Set-Variable and Out-File commands. These commands support the WhatIf parameter. The Tee-Object command doesn't support the WhatIf parameter. However, if you wrap Tee-Object in a script or function that support the WhatIf parameter, Tee-Object passes the state of WhatIf to the Set-Variable and Out-File commands.
Tee-Object [-InputObject <PSObject>] [-FilePath] <String> [-Append] [<CommonParameters>]Tee-Object [-InputObject <PSObject>] -LiteralPath <String> [<CommonParameters>]Tee-Object [-InputObject <PSObject>] -Variable <String> [<CommonParameters>]
Output processes to a file and to the console
Get-Process | Tee-Object -FilePath "C:\Test1\testfile2.txt"IdentifyOutput processes to a variable and Select-Object
Get-Process notepad | Tee-Object -Variable proc | Select-Object ProcessName, HandlesIdentifyOutput system files to two log files
Get-ChildItem -Path D: -File -System -Recurse |
Tee-Object -FilePath "C:\test\AllSystemFiles.txt" -Append |
Out-File C:\test\NewSystemFiles.txtIdentifyUse Tee-Object in a script with the WhatIf parameter
PS> function Test-Tee {
[Cmdletbinding(SupportsShouldProcess)]
Param()
$true|tee -Variable b
"Variable $b is set to '$b'"
}
PS> Test-Tee
True
Variable $b is set to 'True'
PS> Test-Tee -WhatIf
True
What if: Performing the operation "Set variable" on target "Name: b Value: True".
Variable $b is set to ''IdentifyIts page in the reference: Tee-Object.
Parameters
-AppendIndicates 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.-FilePathSpecifies a file that this cmdlet saves the object to Wildcard characters are permitted, but must resolve to a single file.-InputObjectSpecifies 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.-LiteralPathSpecifies 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.-VariableSpecifies a variable that the cmdlet saves the object to. Enter a variable name without the preceding dollar sign ($).