CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

PowerShell – How to access Clipboard?

Clipboard is a buffer in computer memory, allows the applications to copy and retrieve the temporary data.  Most of the applications provides the Clipboard feature to share the temporary data across the applications. Most common way we can use the Clipboard is using cut, copy and paste commands. 

PowerShell provides cmdlets to use the Clipboard.

Retrieve data from Clipboard

PowerShell provides Get-Clipboard cmdlet to get the data stored in the Clipboard.

PS C:\> Get-Clipboard
CodeSteps

Data can contain text, images or media information. If Clipboard contains an image, by using -Format parameter with the value Image we can retrieve the  image details. For example, here is the below command shows the details of the image copied to the Clipboard;

PS C:\> Get-Clipboard -Format Image

Tag                  :
PhysicalDimension    : {Width=240, Height=360}
Size                 : {Width=240, Height=360}
Width                : 240
Height               : 360
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        : {}

When we copy the selected files from an Explorer into the Clipboard; that information we can retrieve using Get-Clipboard command. But, we need to pass FileDropList value through the -Format parameter. Here is an example;

PS C:\> Get-Clipboard -Format FileDropList

    Directory: C:\Sample Pictures

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---l        14-07-2009     11:02         595284 Hydrangeas.jpg
-a---l        14-07-2009     11:02         879394 Chrysanthemum.jpg
-a---l        14-07-2009     11:02         845941 Desert.jpg

Copy data to Clipboard

PowerShell provides Set-Clipboard cmdlet to copy the data to Clipboard. Below example shows this;

PS C:\> Set-Clipboard "Hello!"
PS C:\> Get-Clipboard
Hello!

To clear the data from the Clipboard, just we need to call this command without passing any values;

PS C:\> Set-Clipboard

Sometimes, it is required to append the data to the existing data in the Clipboard instead of replacing it; for this, we need to pass a parameter -Append. Here it looks like;

PS C:\> Set-Clipboard "Powershell" -Append
PS C:\> Get-Clipboard
Hello!
Powershell

[..] David

PowerShell – How to access Clipboard?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top