Monday, June 20, 2022

How to Copy data from PowerShell Commandline to Clipboard

Just today I found out that we can copy the results of a DOS/PowerShell command directly to the Windows Clipboard. It is possible to use the pipe operator for this purpose.

How to copy ipconfig data to clipboard PowerShell command

ipconfig /all | clip

Copy from commandline ipconfig to clipboard


The pipe-sign will pipe the output of the ipconfig command over to the clipboard from where you'll be able to paste it into any text editor of your choices such as Notepad, Notepad++, or VS Code.

How to copy present working directory console output to clipboard using Windows PowerShell

You can use this technique in a combination with various commands including the PWD(Present Working Directory) command i.e.

pwd | clip

Copy present working directory to clipboard from PowerShell commandline


If you want to copy some random text over to the clipboard, it is also possible.

How to copy random text to clipboard using PowerShell

echo "Copy this" | clip

Copy any text co clipboard from cmd or Windows PowerShell


How to clear Windows clipboard from PowerShell command

If you want to clear the clipboard, you can pass an empty string through the echo using the following syntax:

echo "" | clip

Clear clipboard Windows Powershell Commandline command


In case of PowerShell

echo $null | clip


You may use the PowerShell method Get-Clipboard and Set-Clipboard in some scenarios as well although I'm not sure what those specific scenarios could be.

In some cases, you may use the stream redirection operation for the same purpose too. 

I hope you'll find this tech tip blog post useful. Feel free to share if you too know anything cool.

And just an "oh by the way" I also found out about the Get-Content command today which can be used to print the contents of a text file to the console. I believe it has got some other sophisticated uses too. But the simplest one I've found so far is a replacement of the Linux cat command(which is also available in PowerShell). 

All in all, I showed you the following three commands in this short blog post: 


ipconfig /all | clip

pwd | clip

echo "" | clip


1 comment:

Feel free to talk back...