Send the input object(s) to two places, an input object is piped to a file or variable, and then also passed along the pipeline.
Syntax Tee-Object [-inputObject psobject] [-filePath] string [-Append] [CommonParameters] Tee-Object [-inputObject psobject] -LiteralPath string [CommonParameters] Tee-Object [-inputObject psobject] -variable string [CommonParameters] Key -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. -inputObject psobject The object to tee. Enter a variable, command or expression that gets the objects. When you use -InputObject, instead of piping command results to Tee-Object, the -InputObject value, even if the value is a collection that is the result of a command, such as `InputObject (Get-Process)` is treated as a single object. Because -InputObject cannot return individual properties from an array or collection of objects, it is recommended that if you use Tee-Object to perform operations on a collection of objects for those objects that have specific values in defined properties, you use Tee-Object in the pipeline -filePath string Save the input object(s) to a file named string. Wildcard characters are permitted, but must resolve to a single file. -LiteralPath string A file that this cmdlet saves the object to. Unlike -FilePath, the value of -LiteralPath 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. -variable string Assign the input object(s) to a variable named string. Enter a variable name without the preceding dollar sign ($)
Standard Aliases for Tee-Object: tee
Get a list of the processes running and send to a file and also the console:
PS C:\> get-process | tee-object -filepath C:\fileA.txt
Get a list of the processes running and send to two files at once:
PS C:\> get-process | tee-object -filepath C:\fileA.txt | out-file C:\fileB.txt
Save a list of processes to a variable (myprocs) then use Tee-Object to save the myprocs to file and also display on the console:
PS C:\> $myprocs = Get-Process |Select-Object processname,handles
PS C:\> Tee-Object -inputObject $myprocs -filepath C:\fileC.txt
Save all the properties of the notepad process to a variable and then select and display just the ProcessName and Handles:
PS C:\> get-process notepad | tee-object -variable proc | select-object processname,handles
Save a list of system files in a two log files, a cumulative file and a current file:
PS C:\> Get-ChildItem -Path D: -File -System -Recurse | Tee-Object -FilePath "c:\test\AllSystemFiles.txt" -Append | Out-File c:\test\NewSystemFiles.txt
“Two roads diverged in a wood, and I, I took the one less traveled by,And that has made all the difference” ~ Robert Frost (The Road Not Taken)
Out-File - Send command output to a file.
Group-Object - Group the objects that contain the same value for a common property.
Select-Object - Select objects based on parameters set in the Cmdlet command string.
Sort-Object - Sort the input objects by property value.
Where-Object - Filter input from the pipeline allowing operation on only certain objects.
Write-Output - Write an object to the pipeline.
Equivalent bash command: tee - Redirect output to multiple files.