How to use Set-Clipboard and Get-Clipboard in PowerShell
PowerShell provide a cmdlet for use the clipboard, advanced applications are allowed, from PowerShell save multible items to the clipboard to use later, it is possible to append content to already pasted items in the clipboard.
Use Set-Clipboard in PowerShell
Use the PowerShell cmdlet Set-Clipboard to copy a text to the clipboard.
Set-Clipboard "but this to clipboard.."
Use Get-Clipboard in PowerShell
Use the text you just copied can be retrieved with Get-Clipboard.
Use Set-Clipboard with -Append copy a text to the existing one.
Write-Output "append something to" | Set-Clipboard -Append
This the query again with Get-Clipboard.
Delete clipboard content
The following command deletes the contents on the clipboard.
Write-Host "delete items in clipboard.." $null | clip
Retrieve files and folders from Clipboard
And there is even more to go, if you want to retrieve files and folders that are to be copied from the clipboard, the following command gives the output.
Get-Clipboard -Format FileDropList
It is also useful to copy the text content of files directly without opening the file to clipboard, such as scripts or source code.
Use Get-Content with clipboard
Get-Content copies the content of test.bat to the clipboard.
Get-Content test.bat | clip
Compare-Object compares the content and copies it to the clipboard.
Compare-Object $(Get-Content c:\temp\test.bat) $(Get-Content c:\temp\test1.bat) | clip
The default of Compare-Object is not case sensitive, use the parameter -CaseSensitive to distinguish small and capital letters.
Help with examples for use can be found with Get-Help.
Get-Help Set Clipboard -Detailed
Get-Help Get Clipboard -Detailed
Commonly, in Windows the text or content is copied to the clipboard by pressing the “CTRL+C” shortcut key. However, in PowerShell, the text can also be copied to the clipboard using the “Set-Clipboard” cmdlet. This cmdlet sets the content to the clipboard. Moreover, the copied cmdlets can be pasted too in PowerShell using the “Get-Clipboard” cmdlet.
The following post will elaborate on the method to copy the content to the clipboard.
Using PowerShell Copy to Clipboard Function
As described earlier, the copy to clipboard function in PowerShell sets the text or content to the clipboard. The command used for that purpose is the “Set-Clipboard”. Examples explaining the procedure to copy the text to the clipboard are explained.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?