Set-Clipboard in PowerShell Core on Windows Results in Throwing CommandNotFoundException
See original GitHub issueSet-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:
- Created 6 years ago
- Reactions:4
- Comments:14 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As a stopgap, here are functions
Set-ClipboardText
andGet-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 toSet-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).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