Set-Clipboard
Sets the contents of the clipboard.
Syntax
Default (Standardwert)
Set-Clipboard
[-Value] <string[]>
[-Append]
[-PassThru]
[-AsOSC52]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Beschreibung
The Set-Clipboard
cmdlet sets the contents of the clipboard.
Note
On Linux, this cmdlet requires the xclip
utility to be in the path. On macOS, this cmdlet uses
the pbcopy
utility.
Beispiele
Example 1: Copy text to the clipboard
Set-Clipboard -Value "This is a test string"
Example 2: Copy the contents of a file to the clipboard
This example pipes the contents of a file, a public ssh key, to the clipboard. Then, the key can be pasted into another application, like GitHub.
Get-Content C:\Users\user1\.ssh\id_ed25519.pub | Set-Clipboard
Example 3: Copy text to the clipboard of the local host over an SSH remote session
The AsOSC52 parameter allows you to set the clipboard of the local machine when connected to a remote session over SSH.
Set-Clipboard -Value "This is a test string" -AsOSC52
Example 4: Set the default value of the **AsOSC52** parameter
You can detect if you are connected to a remote session over SSH by checking the value of the
$Env:SSH_CLIENT
or $Env:SSH_TTY
environment variables. If either of these variables are set,
then you are connected to a remote session over SSH. You can use this information to set the default
value of the AsOSC52 parameter. Add one of the following lines to your PowerShell profile
script.
$PSDefaultParameterValues['Set-Clipboard:AsOSC52'] = $Env:SSH_CLIENT
$PSDefaultParameterValues['Set-Clipboard:AsOSC52'] = $Env:SSH_TTY
For more information about $PSDefaultParameterValues
, see
about_Parameters_Default_Values.
Parameter
-Append
Indicates that the cmdlet should add to the clipboard instead of replacing it. By default, the cmdlet clears the current content from the clipboard and sets it to the new content. When this parameter is specified, the cmdlet appends the new content after a newline to the current content.
Parametereigenschaften
Typ: | SwitchParameter |
Standardwert: | None |
Unterstützt Platzhalter: | False |
Nicht anzeigen: | False |
Parametersätze
(All)
Position: | Named |
Obligatorisch.: | False |
Wert aus Pipeline: | False |
Wert aus Pipeline nach dem Eigenschaftsnamen: | False |
Wert aus verbleibenden Argumenten: | False |
-AsOSC52
When connected to a remote session over SSH, Set-Clipboard
sets the clipboard of the remote
machine, not the local host. When you use this parameter, Set-Clipboard
uses the OSC52 ANSI escape
sequence to set the clipboard of the local machine.
For this feature to work, your terminal application must support the OSC52 ANSI escape sequence. The Windows Terminal supports this feature.
This parameter was added in PowerShell 7.4.
Parametereigenschaften
Typ: | SwitchParameter |
Standardwert: | None |
Unterstützt Platzhalter: | False |
Nicht anzeigen: | False |
Aliase: | ToLocalhost |
Parametersätze
(All)
Position: | Named |
Obligatorisch.: | False |
Wert aus Pipeline: | False |
Wert aus Pipeline nach dem Eigenschaftsnamen: | False |
Wert aus verbleibenden Argumenten: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
Parametereigenschaften
Typ: | SwitchParameter |
Standardwert: | False |
Unterstützt Platzhalter: | False |
Nicht anzeigen: | False |
Aliase: | cf |
Parametersätze
(All)
Position: | Named |
Obligatorisch.: | False |
Wert aus Pipeline: | False |
Wert aus Pipeline nach dem Eigenschaftsnamen: | False |
Wert aus verbleibenden Argumenten: | False |
-PassThru
Returns an object representing the item with which you're working. By default, this cmdlet does not generate any output.
Parametereigenschaften
Typ: | SwitchParameter |
Standardwert: | False |
Unterstützt Platzhalter: | False |
Nicht anzeigen: | False |
Parametersätze
(All)
Position: | Named |
Obligatorisch.: | False |
Wert aus Pipeline: | False |
Wert aus Pipeline nach dem Eigenschaftsnamen: | False |
Wert aus verbleibenden Argumenten: | False |
-Value
The string values to be added to the clipboard.
Parametereigenschaften
Typ: | String[] |
Standardwert: | None |
Unterstützt Platzhalter: | False |
Nicht anzeigen: | False |
Parametersätze
(All)
Position: | Named |
Obligatorisch.: | True |
Wert aus Pipeline: | True |
Wert aus Pipeline nach dem Eigenschaftsnamen: | True |
Wert aus verbleibenden Argumenten: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet isn't run.
Parametereigenschaften
Typ: | SwitchParameter |
Standardwert: | False |
Unterstützt Platzhalter: | False |
Nicht anzeigen: | False |
Aliase: | wi |
Parametersätze
(All)
Position: | Named |
Obligatorisch.: | False |
Wert aus Pipeline: | False |
Wert aus Pipeline nach dem Eigenschaftsnamen: | False |
Wert aus verbleibenden Argumenten: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Eingaben
String
You can pipe a string containing the content to set to the clipboard to this cmdlet.
Ausgaben
None
This cmdlet returns no output.
Hinweise
PowerShell includes the following aliases for Set-Clipboard
:
- All platforms:
scb
Support for this cmdlet on macOS was added in the PowerShell 7.0.0 release.