The following post will elaborate on the method to copy the content to the clipboard.
Using PowerShell Copy to Clipboard Function
As described earlier, the copy to clipboard function in PowerShell sets the text or content to the clipboard. The command used for that purpose is the “Set-Clipboard”. Examples explaining the procedure to copy the text to the clipboard are explained below.
Example 1: Copy the Text to the Clipboard Using the “Set-Clipboard” Cmdlet
The following illustration will demonstrate the procedure to copy the stated text into the clipboard:
In the above-stated code:
- First, specify the “Write-Output” cmdlet followed by the text within inverted double quotes.
- Then, add the “|” pipeline parameter to make the previous cmdlet’s output be sent to the next.
- Lastly, add the “Set-Clipboard” cmdlet:
Execute the below cmdlet to verify whether the content was copied to the clipboard or not:
Example 2: Append the Text to the Existing Clipboard
To append the content or text to the existing copied content simply add the “-Append” parameter at the end of the code line:
Verify whether the content was copied to the clipboard or not by executing the given cmdlet:
Example 3: Copy the Variable Assigned Content to the Clipboard
The following example will demonstrate the procedure to copy the variable assigned text to the clipboard:
Set-Clipboard -Value $greetings
According to the above code:
- First, initialize a variable and assign the text to it.
- Then, in the next line write the “Set-Clipboard” cmdlet.
- After that, add the “-Value” parameter and assign the text assigned variable:
Execute the “Get-Clipboard” cmdlet to verify whether the content was copied to the clipboard or not:
That was all about copying items to the clipboard.
Conclusion
The “Set-Clipboard” cmdlet in PowerShell is utilized to copy the content or text to the clipboard. It can set the text or variables to the clipboard by using some specific parameters. Moreover, the copied text can be pasted using the “Get-Clipboard” cmdlet. This post has elaborated on the process to copy or set the content to the clipboard in PowerShell.