StUffz
StUffz

Reputation: 123

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.

Upvotes: 1

Views: 243

Answers (2)

user4003407
user4003407

Reputation: 22132

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

Upvotes: 2

srg
srg

Reputation: 275

My assumption is that pipe output for dir is object rather than a plain text that set-clipboard can't just copy, you need to kind of expand or convert it into a string before you copy it to clipboard, try this [string[]] (dir) | Set-Clipboard

Upvotes: 2

Related Questions