Using PowerShell Copy to Clipboard Function


The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

PowerShell has a cmdlet that allows you to copy text from the clipboard to your code editor. Here’s how this command works.

PowerShell is a command-line tool that allows users to automate tasks in Windows. The “powershell copy to clipboard shortcut” is a function that can be used in PowerShell to copy text directly to the clipboard.

Using PowerShell Copy to Clipboard Function

The Windows clipboard may be the last thing on your mind while developing PowerShell scripts. We’re all familiar with the Ctrl-C and Ctrl-V keyboard shortcuts for copying and pasting from the clipboard, but most people prefer to use the GUI. It’s not really helpful in our PowerShell routines. Did you know, though, that PowerShell has a copy to clipboard function?

In this tutorial, I’ll show you how to acquire copy and paste capability in PowerShell before showing you the cmdlets that PowerShell offers beginning with version 5.

The clip.exe program was the only means to copy to the clipboard before PowerShell v5.

clip.exe (Old School)

This program has been around for a long time and just functioned. You may have text copied to the clipboard by passing text to clip.exe. This worked, but adding a carriage return after each entry was always a pain.

PS51> Write-Output ‘Hello’ | clip

Copying to clipboard with clip.exeThe PowerShell copy to clipboard function can replace the clip.exe (Old School)

We also didn’t have a simple mechanism to get information from the clipboard. Once the items were copied to the clipboard, we had no choice but to manually paste them. This is no longer the case with the native clipboard instructions!

Get-Clipboard and Set-Clipboard are two cmdlets that tackle this issue considerably better.

Powershell Command: Set-Clipboard

Set-Clipboard takes the place of clip.exe and works in the same way. Set-Clipboard may now be used instead of piping output to clip. When you paste the information someplace, you’ll see that the trailing carriage return is gone.

The string Hello is now the only thing on the clipboard.

PS> Write-Output ‘Hello’ | Set-Clipboard

The Append argument is another helpful feature of Set-Clipboard. The clipboard has traditionally only been able to hold one thing. With Set-Append Clipboard’s argument, you may now add an endless number of objects without deleting the preceding ones.

PS> Write-Output ‘Hello’ | Set-Clipboard -Append

Parameters for Get-Clipboard

You can use Get-Clipboard to comprehend a few other kinds other than plain strings, even if you don’t use Set-Clipboard to transfer data to the clipboard. For example, if you’ve copied a list of files from File Explorer and want to paste it into your PowerShell prompt, just use the Format argument on Get-Clipboard with the FileDropList value.

PS51> Get-Clipboard -Format FileDropList Directory: \MacHomeDownloads Mode LastWriteTime Length Name —- ————- —— —- —— 8/1/2019 10:42 AM 17919094 Directory: \MacHomeDocumentsSnagitAutosaved Captures.localized Mode LastWriteTime Length Name —- ————- —— —- —— 8/1/2019 1:58 PM 169144472 2019-08-01_13-47-55.mp4

It can be seen that it recognizes the data in the clipboard as a list of files. You may also use photos and other things in the same way.

To obtain different attributes about an image, copy it from another program and use supply -Format Image to Get-Clipboard.

PS51> Get-Clipboard -Format Image Tag : PhysicalDimension : {Width=813, Height=113} Size : {Width=813, Height=113} Width : 813 Height : 113 HorizontalResolution : 96 VerticalResolution : 96 Flags : 335888 RawFormat : [ImageFormat: b96b3caa-0728-11d3-9d7b-0000f81ef32e] PixelFormat : Format32bppRgb Palette : System.Drawing.Imaging.ColorPalette FrameDimensionsList : {7462dc86-6180-4c7e-8e3f-ee7333a7a483} PropertyIdList : {} PropertyItems : {}

Manipulation of the clipboard in PowerShell Core

The Get-Clipboard and Set-Clipboard commands are not accessible in PowerShell Core (v6+), however the WindowsCompatibility module may be used to access them. You can utilize Windows PowerShell cmdlets in PowerShell Core thanks to the WindowsCompatibility module.

Run Invoke-WinCommand after installing the WindowsCompatibility module, and wrap your Get-Clipboard and Set-Clipboard references within.

PS622> Invoke-WinCommand -ScriptBlock {‘This is on the clipboard’ | Set-ClipBoard} PS622> Invoke-WinCommand -ScriptBlock {Get-ClipBoard} This is on the clipboard

You can read and write to the clipboard in the same way that you do with Windows PowerShell.


In today’s PowerShell, you can do a lot more with the clipboard. The Get-Clipboard and Set-Clipboard cmdlets have made it easy to transfer data from PowerShell to the clipboard. These cmdlets enable you to copy to the clipboard and intelligently paste from the clipboard using PowerShell.

Check out the comprehensive help for a complete list of the cmdlets:

PS51> Get-Help Set-Clipboard -Detailed PS51> Get-Help Get-Clipboard -Detailed

This will show you all of the different settings that you may experiment with.

The “powershell set-clipboard” is a function that allows you to copy content from the PowerShell console to the clipboard.

Frequently Asked Questions

How do I copy PowerShell output to clipboard?

A: You can right-click on the red PowerShell text, then click Copy to clipboard. This will copy a screenshot of that line as plain text and paste it into your chat window or anywhere else you want.

How do I copy results from PowerShell?

A: To copy results from PowerShell, you can use the Copy-Item cmdlet. You are limited to copying 256KB worth of data at a time with this method though so it may take some time depending on how large your script is.

How do I copy text in PowerShell?

Related Tags

  • copy powershell output to clipboard
  • how to copy from notepad and paste in powershell
  • powershell get-clipboard to variable
  • powershell clear clipboard
  • powershell get-clipboard image

Table of Content