akhi07rx

2 min read

The PowerShell Pipe


The pipe | just takes whatever a command prints and passes it somewhere else. Usually I use it to copy output straight to my clipboard.

echo Hello World | clip

Hit Ctrl+V after that. There it is. No selecting text, no right-clicking, just pipes straight to clipboard.

works with almost anything:

pwd | clip                  # where am I?
ipconfig | clip             # network info
type notes.txt | clip       # file contents
git rev-parse HEAD | clip   # latest commit hash

can pipe into more than just the clipboard.

ipconfig | findstr IPv4     # filter output
dir | sort-object           # sort it
dir | measure-object        # count files
ipconfig > output.txt       # save to file
ipconfig >> output.txt      # append to file

Also, it can be combined. This grabs every running process, keeps only the CPU-heavy ones, sorts them, and shows the top 10:

Get-Process |
Where-Object CPU -gt 100 |
Sort-Object CPU -Descending |
Select-Object -First 10

§clip vs Set-Clipboard

Both work in PowerShell. clip also works in CMD. Set-Clipboard is PowerShell only but a bit cleaner:

ipconfig | Set-Clipboard
Get-Clipboard   # read it back `ctrl+V`