Powershell-找不到Windows.剪贴板
我对Powershell和cmd有问题。我有一个引用剪贴板的脚本Powershell-找不到Windows.剪贴板,windows,powershell,cmd,clipboard,Windows,Powershell,Cmd,Clipboard,我对Powershell和cmd有问题。我有一个引用剪贴板的脚本 [System.Windows.Clipboard]::SetText("My text"); 我在Powershell编辑器中运行脚本,一切正常。当我试着从命令行运行它时 powershell.exe -c myscript.ps1 我收到以下错误:找不到类型[System.Windows.Clipboard] (我把它从法语翻译过来,我想这是英语中的对等词) 有什么想法吗?就像@AnthonyStringer所说的,我必须
[System.Windows.Clipboard]::SetText("My text");
我在Powershell编辑器中运行脚本,一切正常。当我试着从命令行运行它时
powershell.exe -c myscript.ps1
我收到以下错误:找不到类型[System.Windows.Clipboard]
(我把它从法语翻译过来,我想这是英语中的对等词)
有什么想法吗?就像@AnthonyStringer所说的,我必须首先用命令导入PresentationCore
Add-Type -Assembly PresentationCore
这样,当从cmd调用powershell时,它可以调用Windows.Clipboard。首先运行这个
Add Type-Assembly PresentationCore
,它解决了我的问题!谢谢@AnthonyStringer:)