Posted: . At: 9:14 AM. This was 8 years ago. Post ID: 9354
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to pipe the output of a Windows command to the clipboard.

Pipe text to the clipboard from Windows CMD

Apparently, there is an obscure feature in the Windows CMD prompt that allows users to pipe the output of a Windows CMD command on STDOUT to the Windows clipboard. The clip command allows this.

For example.

C:\Users\johnc>ipconfig | clip

This will pipe the IP addressing information for your machine to the clipboard. This could be a useful feature when using a Windows machine and the user is wanting to copy a lot of text from the CMD window to the clipboard. In Powershell there are the cmdlets Set-Clipboard and Get-Clipboard that send text to the clipboard and also retrieve text from the clipboard. Very interesting feature that we have just been reminded of even though it apparently existed since Windows Vista.

To retrieve the contents of the clipboard, this cmdlet in Powershell will do the trick.

PS C:\Users\johnc> Get-Clipboard
C:\Users\johnc>ipconfig | clip

And to put text into the clipboard.

PS C:\Users\johnc> Get-NetAdapterHardwareInfo | Set-Clipboard

And we can retrieve this from the clipboard thusly.

PS C:\Users\johnc> Get-Clipboard
MSFT_NetAdapterHardwareInfoSettingData: MSFT_NetAdapterHardwareInfoSettingData 'Realtek PCIe FE Family Controller' (Inst
anceID = "{6E02DD8D-97C1-4FB4-AB1B-84684B76BD53}")
MSFT_NetAdapterHardwareInfoSettingData: MSFT_NetAdapterHardwareInfoSettingData 'Dell Wireless 1703 802.11b|g|n (2.4GHz)'
 (InstanceID = "{F23C4AFD-C2DA-4028-A5EF-80121D557A52}")

This is how easy it is to read and write to the clipboard using the CMD and Powershell command line shells in Windows. I hope that this is very useful for any Windows user who wants to make more use of Powershell in Windows.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.