Microsoft introduces new cmdlets in PowerShell v5 to copy and paste text, image, … It means that you can use Windows PowerShell to easily send output to the clipboard. You’ll find that being able to copy and paste to and from the clipboard via PowerShell can be a useful task. We now have two cmdlets:
- Get-Clipboard: Gets the current Windows clipboard entry.
- Set-Clipboard: Sets the current Windows clipboard entry.
You can pipe output to the Set-Clipboard cmdlet:
PS > "Hello World!" | Set-Clipboard
Now I can use the Get-Clipboard cmdlet to check that the clipboard only contains the string “Hello World!”
PS > Get-Clipboard Hello World!
I can also send the directory list of the current folder to my clipboard:
PS > gci | Set-Clipboard
Don’t forget to add the -Format parameter with FileDropList value to display the result:
PS > Get-Clipboard -Format FileDropList | ft basename, LastAccessTime BaseName LastAccessTime -------- -------------- Contacts 12/17/2016 18:30:40 Desktop 03/05/2017 14:45:14 Documents 03/04/2017 12:02:52 Downloads 03/05/2017 14:45:14 Favorites 12/17/2016 18:30:40 Links 12/17/2016 18:30:42 Music 12/17/2016 18:30:40 OneDrive 12/18/2016 12:06:20 Pictures 12/17/2016 18:57:38 Privax Ltd 12/18/2016 12:47:17 Saved Games 12/17/2016 18:30:41 Searches 12/17/2016 18:32:44 Videos 12/17/2016 18:30:40
Thanks for reading! You can follow me on Twitter @PrigentNico