Showing posts with label Add-Type. Show all posts
Showing posts with label Add-Type. Show all posts

Monday, January 9, 2012

Reading the Clipboard using Powershell

 

PowerTip of the Day, from PowerShell.com:

 

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.

Thanks

Aman