Send object to multiple targets in PowerShell

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

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish