Get and Set Clipboard in Powershell

Posted Saturday, January 14, 2012 in Old JamesCMS Posts

Here are two function to get and set the clipboard. If your familiar with the method of using the windows forms class be warned, that method has a limited data length.

function Git-Clipboard {            
    powershell -noprofile -sta -command {add-type -assembly presentationcore;[windows.clipboard]::gettext()}            
function Set-Clipboard {            
    $text | outfile “tempClipboardText.txt”            
    powershell -noprofile -sta -command {add-type -assembly presentationcore;[windows.clipboard]::settext([string]::join([environment]::newline, (get-content “tempClipboardText.txt”)))}            
	del “tempClipboardText.txt”