Reading the Clipboard

by Jan 5, 2012

What if you wanted to paste information from the clipboard? No sweat, here is a Get-Clipboard function that outputs any text held by the clipboard:

function Get-Clipboard {
 Add-Type -AssemblyName System.Windows.Forms 
 $tb = New-Object System.Windows.Forms.TextBox 
 $tb.Multiline = $true 
 $tb.Paste() 
 $tb.Text 
}

In a previous tip we presented the corresponding Out-Clipboard function, so now you could send information to the clipboard in one PowerShell session and read it back from another.

Twitter This Tip!
ReTweet this Tip!