Search code examples
powershellpowershell-5.0

Powershell 5 clipboard - manually pasting "complex" clipboard content doesn't work


I just installed Win10 on my notebook and took a first look at all the new commandlets.

While using simple text like:

PS C:\Users\SudoSandwich> $do = echo "sad"
PS C:\Users\SudoSandwich> $do | Set-Clipboard

and manually pasting it in Notepad for example works just fine, I'm having trouble with some more "complex" clipboard content. Let's use dir | Set-Clipboard. I know that in the console you have to use Get-Clipboard -Format FileDropList to get it back, but what about pasting the results of dir into notepad? Appearantly pasting is disabled in that case.

Anyone figured out why this doesn't work yet? The oldschool way of selecting the output in the console and pasting it in notepad still works fine.


Solution

  • You can use Out-String cmdlet to convert any complex object to the text you normally see on console. Then you can copy that text to clipboard:

    dir | Out-String | Set-Clipboard