PoshTip #43 – Copy and Paste with Clipboard from PowerShell

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:

Now I can use the Get-Clipboard cmdlet to check that the clipboard only contains the string « Hello World! »

I can also send the directory list of the current folder to my clipboard:

Don’t forget to add the -Format parameter with FileDropList value to display the result:

 

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 216 Articles
I work as a System Engineer, based in Switzerland with a primary focus on Microsoft technologies. I have 7 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSA: Windows Server 2012" and "Administering & Deploying SCCM" certified.