Get-Clipboard
Gets the contents of the clipboard.
Syntax
Default (Default)
Get-Clipboard
[-Raw]
[-Delimiter <String[]>]
[<CommonParameters>]
Description
The Get-Clipboard cmdlet gets the contents of the clipboard as text. Multiple lines of text are
returned as an array of strings similar to Get-Content.
Note
On Linux, this cmdlet requires the xclip utility to be in the path. On macOS, this cmdlet uses
the pbpaste utility.
Examples
Example 1: Get the content of the clipboard
Set-Clipboard -Value 'hello world'
Get-Clipboard
hello world
Example 2: Get the content of the clipboard using a custom delimiter
This example gets the content of the clipboard. The content is a string containing the pipe
character. Get-Clipboard splits the content at each occurrence of the specified delimiter.
Set-Clipboard -Value 'line1|line2|line3'
Get-Clipboard -Delimiter '|'
line1
line2
line3
Example 3: Get the content of the clipboard using custom delimiters
This example gets the content of the clipboard delimited by the line ending for both Windows and Linux.
Get-Clipboard -Delimiter "`r`n", "`n"
Parameters
-Delimiter
Specifies one or more delimiters to use when the clipboard content is returned as an array of
strings. The command splits the contents of the clipboard at each occurrence of any of the specified
delimiters. If not specified, the default delimiter is [Environment.NewLine].
- On Windows, the default delimiter is
"`r`n". - On Linux and macOS, the default delimiter is
"`n".
Parameter properties
| Type: | String[] |
| Default value: | Platform specific newline |
| 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 |
-Raw
Gets the entire contents of the clipboard. Multiline text is returned as a single multiline string rather than an array of strings.
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 |
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
None
You can't pipe objects to this cmdlet.
Outputs
String
By default, this cmdlet returns the content as an array of strings, one per line. When you use the Raw parameter, it returns a single string containing every line in the file.
Notes
PowerShell includes the following aliases for Get-Clipboard:
- All platforms:
gcb
Support for this cmdlet on macOS was added in the PowerShell 7.0.0 release.