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

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.

No comments have been made. Use this form to start the conversation :)

Leave a Reply