question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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


Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
mklement0commented, Dec 30, 2017

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

4reactions
SteveL-MSFTcommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set-Clipboard (Microsoft.PowerShell.Management)
Returns an object representing the item with which you're working. By default, this cmdlet does not generate any output. Type: SwitchParameter. Position: Named....
Read more >
PowerShell 6.2.4 : Get-Clipboard' is not recognized as the ...
PowerShell 6.2. 4 : Get-Clipboard' is not recognized as the name of a cmdlet - Stack Overflow.
Read more >
PowerShell - CommandNotFoundException - Microsoft Q&A
I have a strange error with the PowerShell and a simple command: New-LocalGroup -Description "Test Usergroup" -Name Testsusers.
Read more >
Tag Archives: Set-Alias - tommymaynard.com
One command alias is from the Microsoft.PowerShell.Utility module and six are from the Microsoft.PowerShell.Management module. It is not like there are only one ......
Read more >
Windows PowerShell Cookbook - Bienvenue sur LinuxCLG
A Guided Tour of Windows PowerShell breezes through PowerShell at a high level. It introduces PowerShell's core features: • An interactive shell.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found