Clipboard cmdlets

The clipboard cmdlets return in PowerShell v7 preview 6

Get-Clipboard and Set-Clipboard are back and according to the release notes work cross platform.

PS> Get-Command Get-Clipboard -Syntax

Get-Clipboard [-Raw] [<CommonParameters>]

PS> Get-Clipboard
Clipboard test

The Raw parameter makes Get-Clipboard ignore new line characters and get the entire contents of the clipboard.

PS> Get-Clipboard -Raw
Clipboard test

Clipboard test2

Putting values onto the clipboard:

PS> Get-Command Set-Clipboard -Syntax

Set-Clipboard [-Value] <string[]> [-Append] [-WhatIf] [-Confirm] [<CommonParameters>]

PS> Set-Clipboard -Value ‘new clipboard’ –Append

PS> Get-Clipboard -Raw
Clipboard test

Clipboard test2
new clipboard

The clipboard can be cleared – more or less – with a blank string

Set-Clipboard -Value ‘ ‘

On Linux, Set-Clipboard requires the xclip utility to be in the path.

This entry was posted in PowerShell 7. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s