RandomSecGuy
RandomSecGuy

Reputation: 41

Powershell - Windows.Clipboard not found

I have a problem with Powershell and cmd. I have a script that reference the clipboard

[System.Windows.Clipboard]::SetText("My text");

I run the script in the Powershell editor and eveything goes fine. When I tried running it from the commandline

powershell.exe -c myscript.ps1

I get this error: Type [System.Windows.Clipboard] not found

(I translate it from French, I suppose this is the equivalent in english)

Any idea?

Upvotes: 2

Views: 767

Answers (1)

RandomSecGuy
RandomSecGuy

Reputation: 41

Like @AnthonyStringer said, I had to import first the PresentationCore with the command

Add-Type -Assembly PresentationCore

This way, when calling powershell from the cmd it was able to call Windows.Clipboard.

Upvotes: 2

Related Questions