You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Set-Clipboard in PowerShell Core on Windows Results in Throwing CommandNotFoundException #4307
Set-Clipboard throws a CommandNotFoundException in PowerShell Core on Windows. There is a similar issue #3618 open for Mac. A workaround could be piping to clip.exe in Windows but this passes functionality out of PowerShell.
Steps to reproduce
Get-Content-Path myfile.txt |Set-Clipboard
Expected behavior
Text piped or passed into command should get set to the clipboard.
Actual behavior
Get-Content-Path myfile.txt |Set-ClipboardSet-Clipboard : The term 'Set-Clipboard' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:32+Get-Content-Path myfile.txt |Set-Clipboard+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-Clipboard:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Environment data
$PSVersionTable
Name Value
---------
PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.4
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reacted by Friedrich von Never, ExE Boss and Eric Bourland
Ilya (@iSazonov) Clipboard class is part of WinForms so no hope of having it in corefx. Personally, I think the cmdlets are useful, but we'll have to use native apis to make it work.
PSReadline needs this functionality as well, but I would probably just copy the code so the dependency on WinForms can be removed completely (not use WinForms with full clr.)
As a stopgap, here are functions Set-ClipboardText and Get-ClipboardText that work with both editions (Windows PowerShell and PowerShell Core) on all supported platforms.
In PowerShell Core, they use clip.exe, pbcopy / pbpaste, xclip on Windows / macOS / Linux, and on Windows PowerShell they use WinForms on v5.0- and defer to Set-Clipboard / Get-Clipboard on v5.1+.
The caveat is that, on Linux platforms, xclip is neither preinstalled nor guaranteed to be available (different Linux desktop environments have different utilities).
Reacted by Ilya, Steve Lee, Eska látor!, Marc Kassay, Kai Sellgren and Tarik Guney
The cmdlets is documented for Windows PowerShell. Maybe for PowerShell Core we could replace the articles with link on Michael Klement (@mklement0) module?
Activity
MaximoTrinidad commentedon Jul 20, 2017
Hum! Set-Clipboard doesn't exist in PowerShell Core (yet).
:)
iSazonov commentedon Jul 20, 2017
Steve Lee (@SteveL-MSFT) Have we plans to port Get/Set-Clipboard cmdlets? On Windows? On Unix?
SteveL-MSFT commentedon Jul 20, 2017
Ilya (@iSazonov) Clipboard class is part of WinForms so no hope of having it in corefx. Personally, I think the cmdlets are useful, but we'll have to use native apis to make it work.
lzybkr commentedon Jul 23, 2017
PSReadline needs this functionality as well, but I would probably just copy the code so the dependency on WinForms can be removed completely (not use WinForms with full clr.)
mklement0 commentedon Dec 30, 2017
As a stopgap, here are functions
Set-ClipboardTextandGet-ClipboardTextthat work with both editions (Windows PowerShell and PowerShell Core) on all supported platforms.In PowerShell Core, they use
clip.exe,pbcopy/pbpaste,xclipon Windows / macOS / Linux, and on Windows PowerShell they use WinForms on v5.0- and defer toSet-Clipboard/Get-Clipboardon v5.1+.The caveat is that, on Linux platforms,
xclipis neither preinstalled nor guaranteed to be available (different Linux desktop environments have different utilities).SteveL-MSFT commentedon Jan 2, 2018
Michael Klement (@mklement0) perhaps you can wrap it as a module and publish to PowerShell Gallery?
mklement0 commentedon May 22, 2018
Steve Lee (@SteveL-MSFT): Your wish is my (belated) command: I've published module
ClipboardText:Gallery link: https://www.powershellgallery.com/packages/ClipboardText
Repo link (overview): https://github.com/mklement0/ClipboardText
SteveL-MSFT commentedon May 22, 2018
I think Michael Klement (@mklement0)'s module is a fine solution to this issue.
iSazonov commentedon May 23, 2018
How can we make better discoverability for this module?
SteveL-MSFT commentedon May 23, 2018
Ilya (@iSazonov) well, I tweeted it so that helps. Perhaps someone can add it to https://github.com/janikvonrotz/awesome-powershell?
iSazonov commentedon May 23, 2018
The cmdlets is documented for Windows PowerShell. Maybe for PowerShell Core we could replace the articles with link on Michael Klement (@mklement0) module?
SteveL-MSFT commentedon May 23, 2018
Ilya (@iSazonov) if we ever get around to implementing #1982, I think that should solve the discovery problem
SteveL-MSFT commentedon Mar 1, 2019
Although .Net Core 3.0 brings back WinForms so the Windows implementation of the Clipboard cmdlets may come back, it wouldn't be cross platform compatible. My suggestion is to use code similar to what we have in PSReadLine for cross platform clipboard support: https://github.com/lzybkr/PSReadLine/blob/194c8dba426986f115c61919e8699b0f34fc4b01/PSReadLine/Clipboard.cs#L12