How to copy stdout to the clipboard in Powershell


Suppose you want to copy the output of a Powershell command to the clipboard. Instead of making a mess of selecting the output in the terminal and copying, just pipe the output to clip.

For example to copy your path environment variable to the clipboard run:

1
$Env:Path | clip

The same can also be achieved using Set-Clipboard:

1
$Env:Path | Set-Clipboard

To read the contents of the clipboard use Get-Clipboard:

1
$content = Get-Clipboard

References