Tee-Object

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, -OutVariable.

Examples

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

"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:

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



Back to the Top

Simon Sheppard
SS64.com