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 [-filePath] string [-inputObject psobject] [CommonParameters] Tee-Object -variable string [-inputObject psobject] [CommonParameters] Key -inputObject psobject The object to tee. Enter a variable, command or expression that gets the objects. -filePath string Save the input object(s) to a file named string. -variable string Assign the input object(s) to a variable named string. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
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
“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)
Related PowerShell Cmdlets:
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.