PowerShell Copy To Clipboard

Sometimes copy paste is just really hard. If you’ve ever found yourself working through multiple RDP sessions you’ve probably attempted to copy or paste something in a PowerShell session only to have it fail horribly. Maybe you’ve been trying to look at some returned data only to have it output in some weird list.

CLIP

Struggling to copy the results of a PowerShell command to your clipboard so you can make a note? Rather than highlight the result and try to figure out how to copy based on which editor you are using. Instead just pipe the result to CLIP.

Microsoft last updated the documentation for the clip command in 2017. Essentially it lets you redirect output to the windows clipboard. This enables you to do all kinds of things like.

Get-ChildItem | Select-Object FullName | Clip

Which would get all of the child items in a directory, select their full name and then copy the output to your clipboard. You can of course do this with just about anything that goes through the pipeline. To read more about how clip works check out the Microsoft docs site!

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/clip

Some great uses for this might include when you are trying to diagnose an error message!

Pretty neat right? What if we wanted to take this a step forward. Sometimes when you are first writing some code you might be testing out and re-running a a few try catch loops over and over and capture any errors in your clipboard so you can search for why something failed. Just a little tweaking and no problem!

I’m sure there are tons of other ways you can use this in day to day coding! For me it’s a nice saving grace when I’m working through a web browser session and maybe I can’t use Ctrl+c or other options.

If you think of anything that works well feel free to comment down below!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: