首页 > 解决方案 > PowerShell 6.2.4:Get-Clipboard' 未被识别为 cmdlet 的名称

问题描述

我希望Get-Clipboard这个工作

我使用的是 PowerShell 6.2.4 和 MacOs Catalina?

Get-Clipboard : The term 'Get-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 /Users/.../debug.ps1:41 char:1
+ Get-Clipboard
+ ~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-Clipboard:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

标签: powershellclipboard

解决方案


PowerShell [Core] v6.x没有剪贴板 cmdlet - 您必须等待 v7.0才能返回(可用的预览版本有它们)。

链接中的文档 URL 以结尾?view=powershell-7,表示 v7.x 主题;有一个标有“版本”的下拉列表可以选择不同的 PowerShell 版本;如果您选择了6,您会被告知 v6.x 不存在此类页面

与此同时,您有两种选择:

  • 使用特定于平台的工具,例如pbpaste/ pbcopy(macOS) 和xclip(带有基于 X11 桌面的 Linux 发行版)和clip.exe/ System.Windows.FormsWindows 上的程序集。

  • 使用ClipboardText第三方模块(由我编写;repo),它为您包装了上述工具(仅文本支持,通过命令Set-ClipboardTextGet-ClipboardText)。

    • 该模块还适用于Windows PowerShell 版本 v2-v4,它们同样缺少剪贴板实用程序。

推荐阅读