Skip to content

Prints command output to console and also sends it down the pipeline

License

Notifications You must be signed in to change notification settings

DannyMeister/Pee-Object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Pee-Object

When you don't want to cut off your PowerShell pipeline midstream just to print to console.

This git repo has an accompanying blog post here: https://www.dannymeister.com/2019/03/26/pee-object.html

Description

Pee-Object prints command output to console and also sends it down the pipeline.

It's like Tee-Object, but for Printing objects. Just as Tee-Object is aliased tee, Pee-Object is aliased pee.

Uses

This is often useful on one-liner scripts to debug the results of one step in the pipeline before sending it to the next, without having to break your commands onto multiple lines.

It can also be a poor-developer's progress indicator for long running operations in your pipeline.

Example

Get count of all .txt files on hard drives, and print out each drive letter as you begin to process it.

Get-PSDrive -PSProvider FileSystem | pee | %{Get-ChildItem "$_`:`\" -Filter "*.txt" -Recurse -File -ErrorAction SilentlyContinue} | Measure-Object | select Count
C
D
E
F
G

Count
-----
24007

Installation

This didn't seem to deserve a fancy module for importing into your scripts. I would recommend simply dot sourcing the file in your profile so it's handy when the need arises.

In %UserProfile%\My Documents\WindowsPowerShell\profile.ps1 add:

. C:\path\to\Pee-Object.ps1

Disadvantages

Write-Host (on which this command is built) still isn't the best idea in production PowerShell or reusable modules. As of PowerShell 5, it CAN be redirected to not display console messages, but you still have the chance for console/output race conditions.

About

Prints command output to console and also sends it down the pipeline

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages