Powershell

How to Use the Set-Clipboard (Microsoft.PowerShell.Management) Cmdlet in PowerShell?

In Windows, the text is copied to the clipboard using the GUI interface or with the help of the shortcut key “CTRL+C”. However, the same task can also be performed using PowerShell’s “Set-Clipboard” cmdlet. The clipboard’s contents are set with the “Set-Clipboard” cmdlet. The standard alias for the “Set-Clipboard” cmdlet is “clip”.

This article will elaborate on the use of PowerShell’s “Set-Clipboard” cmdlet.

How to Use the Set-Clipboard Cmdlet in PowerShell?

The “Set-Clipboard” cmdlet is used to copy or set the content to the clipboard in PowerShell. To copy the content to the clipboard, first, use the “Set-Clipboard” cmdlet, then specify the text or file path to be copied.

Syntax

The syntax of the “Set-Clipboard” cmdlet is provided below:

Set-Clipboard [-Value] [<CommonParameters>]

Example 1: Use the “Set-Clipboard” Cmdlet to Copy the Text to the Clipboard

To set the content to the clipboard, first, use the “Set-Clipboard” cmdlet, along with the “-Value” parameter, and assign the text:

Set-Clipboard -Value "This text will be copied."

To check whether the content was copied to the clipboard or not by executing the given command:

Get-Clipboard

Example 2: Use the Cmdlet “Set-Clipboard” to Copy the File’s Content to the Clipboard

To copy the file to the clipboard, first, use the “Get-Content” cmdlet and provide the text file value. After that pipe it to the “Set-Clipboard” cmdlet:

Get-Content C:\Users\LinuxHint\Desktop\File.txt | Set-Clipboard

That’s it! You have learned the usage of the “Set-Clipboard” cmdlet in PowerShell.

Conclusion

The “Set-Clipboard” cmdlet in PowerShell is responsible for setting the content or text to the clipboard. To set the content to the clipboard, simply, assign the text or file path to the “Set-Clipboard” cmdlet. This post has explained the use of PowerShell’s “Set-Clipboard” cmdlet.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.