O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.7. Pipeline Tees

Building long command pipelines is a very powerful way to express a complex action. Sometimes, though, we have to get the objects produced by a command somewhere in the middle of our pipeline and store them for future reference. The most common scenario is logging: we need to store a list of objects before acting on them. Say we want to terminate a couple of processes, but we need to write out the victim processes' names to an improvised audit log. Normally, we would get and terminate the processes using Get-Process and Stop-Process like this:

PS> Get-Process notepad | Stop-Process
PS>

To write the objects that Get-Process returned to a file, we need to inject a Tee-Object call in the pipeline:

PS> Get-Process notepad | Tee-Object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required