Subscribe Now

* You will receive the latest news and updates on the Canadian IT marketplace.

Trending News

Blog Post

How to: Copying The Output Of The Last PowerShell Command To Clipboard
HOW TO

How to: Copying The Output Of The Last PowerShell Command To Clipboard 

So to address this, I threw the following small function into my profile:

1
function cc { r | scb }

Now PowerShell 5.0 is needed to evoke this. Specifically for use of Set-Clipboard. Let’s now break down the workings of the small function.

First, I’m defining a function named cc which is not a properly named PowerShell function but for now it will do the trick. Its assigned r | scb in which r is an alias for Invoke-History which re-runs the last command typed. Try it yourself:

1
2
3
4
5
6
7
8
9
10
PS G:\> write-output "hah!"
hah!
 
PS G:\> r
write-output "hah!"
hah!
 
PS G:\> r
write-output "hah!"
hah!

Last but not least scb is an alias for Set-Clipboard which means whatever came out of the last command will be the new contents of your clipboard.

Source: CANITPRO

 

 

Related posts