Skip to content

Set-Clipboard in PowerShell Core on Windows Results in Throwing CommandNotFoundException #4307

Closed

Description

@ephos

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-Clipboard
Set-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

Activity

  1. MaximoTrinidad commented on Jul 20, 2017

    @MaximoTrinidad

    Hum! Set-Clipboard doesn't exist in PowerShell Core (yet).
    :)

  2. iSazonov commented on Jul 20, 2017

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Have we plans to port Get/Set-Clipboard cmdlets? On Windows? On Unix?

  3. added
    WG-Cmdlets
    Up-for-Grabs
    on Jul 20, 2017
  4. SteveL-MSFT commented on Jul 20, 2017

    @SteveL-MSFT
    Member

    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.

  5. lzybkr commented on Jul 23, 2017

    @lzybkr
    Contributor

    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.)

  6. added
    Hacktoberfest
    on Sep 30, 2017
  7. mklement0 commented on Dec 30, 2017

    @mklement0
    Contributor

    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).

  8. SteveL-MSFT commented on Jan 2, 2018

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) perhaps you can wrap it as a module and publish to PowerShell Gallery?

  9. mklement0 commented on May 22, 2018

    @mklement0
    Contributor

    Steve Lee (@SteveL-MSFT): Your wish is my (belated) command: I've published module ClipboardText:

  10. SteveL-MSFT commented on May 22, 2018

    @SteveL-MSFT
    Member

    I think Michael Klement (@mklement0)'s module is a fine solution to this issue.

  11. iSazonov commented on May 23, 2018

    @iSazonov
    Collaborator

    How can we make better discoverability for this module?

  12. SteveL-MSFT commented on May 23, 2018

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) well, I tweeted it so that helps. Perhaps someone can add it to https://github.com/janikvonrotz/awesome-powershell?

  13. iSazonov commented on May 23, 2018

    @iSazonov
    Collaborator

    The cmdlets is documented for Windows PowerShell. Maybe for PowerShell Core we could replace the articles with link on Michael Klement (@mklement0) module?

  14. SteveL-MSFT commented on May 23, 2018

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) if we ever get around to implementing #1982, I think that should solve the discovery problem

  15. SteveL-MSFT commented on Mar 1, 2019

    @SteveL-MSFT
    Member

    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

  16. removed
    Hacktoberfest
    Up-for-Grabs
    on Aug 10, 2019
  17. added
    Resolution-Fixed
    and removed
    WG-Cmdlets
    on Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Resolution-FixedWG-Cmdlets

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions