HomeLinuxUtilizing PowerShell Copy to Clipboard Operate

Utilizing PowerShell Copy to Clipboard Operate


Usually, in Home windows the textual content or content material is copied to the clipboard by urgent the “CTRL+C” shortcut key. Nevertheless, in PowerShell, the textual content may also be copied to the clipboard utilizing the “Set-Clipboard” cmdlet. This cmdlet units the content material to the clipboard. Furthermore, the copied cmdlets might be pasted too in PowerShell utilizing the “Get-Clipboard” cmdlet.

The next publish will elaborate on the tactic to repeat the content material to the clipboard.

Utilizing PowerShell Copy to Clipboard Operate

As described earlier, the copy to clipboard operate in PowerShell units the textual content or content material to the clipboard. The command used for that objective is the “Set-Clipboard”. Examples explaining the process to repeat the textual content to the clipboard are defined beneath.

Instance 1: Copy the Textual content to the Clipboard Utilizing the “Set-Clipboard” Cmdlet

The next illustration will show the process to repeat the acknowledged textual content into the clipboard:

Write-Output “Welcome to Linux Trace!” | SetClipboard

Within the above-stated code:

  • First, specify the “Write-Output” cmdlet adopted by the textual content inside inverted double quotes.
  • Then, add the “|” pipeline parameter to make the earlier cmdlet’s output be despatched to the subsequent.
  • Lastly, add the “Set-Clipboard” cmdlet:

Execute the beneath cmdlet to confirm whether or not the content material was copied to the clipboard or not:

Instance 2: Append the Textual content to the Current Clipboard

To append the content material or textual content to the prevailing copied content material merely add the “-Append” parameter on the finish of the code line:

Write-Output “Append this textual content” | SetClipboard -Append

Confirm whether or not the content material was copied to the clipboard or not by executing the given cmdlet:

Instance 3: Copy the Variable Assigned Content material to the Clipboard

The next instance will show the process to repeat the variable assigned textual content to the clipboard:

$greetings = “Good luck!”
SetClipboard -Worth $greetings

In accordance with the above code:

  • First, initialize a variable and assign the textual content to it.
  • Then, within the subsequent line write the “Set-Clipboard” cmdlet.
  • After that, add the “-Worth” parameter and assign the textual content assigned variable:

Execute the “Get-Clipboard” cmdlet to confirm whether or not the content material was copied to the clipboard or not:

That was all about copying gadgets to the clipboard.

Conclusion

The “Set-Clipboard” cmdlet in PowerShell is utilized to repeat the content material or textual content to the clipboard. It might probably set the textual content or variables to the clipboard by utilizing some particular parameters. Furthermore, the copied textual content might be pasted utilizing the “Get-Clipboard” cmdlet. This publish has elaborated on the method to repeat or set the content material to the clipboard in PowerShell.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments