Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell-找不到Windows.剪贴板_Windows_Powershell_Cmd_Clipboard - Fatal编程技术网

Powershell-找不到Windows.剪贴板

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所说的,我必须

我对Powershell和cmd有问题。我有一个引用剪贴板的脚本

[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:)