Set-Clipboard
Sets the contents of the clipboard.
Syntax
Default (Default)
Set-Clipboard
-Value <String[]>
[-Append]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Set-Clipboard cmdlet sets the contents of the clipboard.
Note
On Linux, this cmdlet requires the xclip utility to be in the path.
Examples
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 to the clipboard. In this example, we are getting a public ssh key so that it can be pasted into another application, like GitHub.
Get-Content C:\Users\user1\.ssh\id_ed25519.pub | Set-Clipboard
Parameters
-Append
Indicates that the cmdlet does not clear the clipboard and appends content to it.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Value
The string values to be added to the clipboard.
Parameter properties
| Type: | String[] |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | True |
| Value from pipeline: | True |
| Value from pipeline by property name: | True |
| Value from remaining arguments: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | 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.
Inputs
String
Notes
In rare cases when using Set-Clipboard with a high number of values in rapid succession, like in a
loop, you might sporadically get a blank value from the clipboard. This can be fixed by using
Start-Sleep -Milliseconds 1 in the loop.