Q
Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

Can I access the clipboard in PowerShell 5.0?

The new version of PowerShell in Windows 10 makes it easier than ever to interact with the clipboard using a few simple commands.

It has been possible to interact with the Windows clipboard from PowerShell for quite some time, but Microsoft made the process much easier in PowerShell 5.0.

In PowerShell 4.0, the easiest way to interact with the clipboard from PowerShell was to call an executable file named clip.exe. For example, if you wanted to copy PowerShell's output to the clipboard, you could write a line of code that would pipe the output to clip.exe.

In PowerShell 5.0, Microsoft introduced new cmdlets that simplify working with the clipboard. One is Get-Clipboard. Upon entering this cmdlet, PowerShell will display any text on the Windows clipboard. Similarly, you can copy text to the Windows clipboard by using the Set-Clipboard cmdlet.

PowerShell 5.0 is a text-based interface, so you would probably expect the Get-Clipboard and Set-Clipboard cmdlets to also be text based. These PowerShell cmdlets work with clipboard text by default, but text is not the only option. PowerShell can also work with file drop lists, audio and video. You can specify the data type by including the Format switch followed by either Text, FileDropList, Image or Audio.

Incidentally, if you do decide to work with text, there is a TextFormatType switch that you can use to specify the type of text that you want to work with. Possible values for this switch include Text, UnicodeText, RTF, HTML and CommaSeparatedValue.

The various clipboard options open up a lot of possibilities for PowerShell scripting. For example, the file drop list support allows you to programmatically select a group of files and take action on those files.

The command syntax isn’t overly difficult, but if you need some help with using the commands then the easiest thing to do is to use the Get-Help cmdlet, followed by the name of the cmdlet that you need help with. For instance: Get-Help Get-Clipboard.

Next Steps

Four useful features in PowerShell 5

Changes in PowerShell 5.0

Dealing with unstructured data in PowerShell

This was last published in July 2016

PRO+

Content

Find more PRO+ content and other member only offers, here.

Essential Guide

The go-to Windows PowerShell guide

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

2 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

How will the clipboard functions in PowerShell 5 help you?
Cancel
So people are still using Windows clipboard...? Far too many far better replacements out there. Now I wonder if i can access one of those programs with powershell...?
Cancel

-ADS BY GOOGLE

SearchVirtualDesktop

SearchWindowsServer

SearchExchange

Close