Send object to multiple targets in PowerShell

Learn how to send output from PowerShell to multiple targets such as pipeline, variable and files.

John Savill

July 21, 2015

1 Min Read
Send object to multiple targets in PowerShell

Q. How can I send objects to a variable/file but still have them continue up the pipeline in PowerShell?

A. Normally objects output from a command can go one direction, for example output could be sent to the screen/file/variable but would not be able to also continue down the pipeline. For example the below would save the list of processes to the variable $procs and would continue sending it down the pipeline which as there is no further command would output to screen.

get-process | tee-object -Variable procs 

Below is an example showing the objects continuing down the pipeline however you would still be able to use $procs to access the objects.

get-process | tee-object -Variable procs | Select-Object processname, id

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like