[bgreco.net]: PS C:\> Get-Clipboard

There are a couple ways of getting the clipboard contents using Windows PowerShell. One common method I've seen works regardless of whether PowerShell is running in MTA mode (the default) or STA mode. However, it can't handle arbitrary lengths of text. The other way only works in STA mode. So, here's a function that will get the full clipboard contents while taking care of the STA stuff for you.

If you'd like to receive the clipboard as an array instead of a chunk of text, pass the -Lines switch.

function Get-Clipboard([switch] $Lines) {
	if($Lines) {
		$cmd = {
			Add-Type -Assembly PresentationCore
			[Windows.Clipboard]::GetText() -replace "`r", '' -split "`n"
		}
	} else {
		$cmd = {
			Add-Type -Assembly PresentationCore
			[Windows.Clipboard]::GetText()
		}
	}
	if([threading.thread]::CurrentThread.GetApartmentState() -eq 'MTA') {
		& powershell -Sta -Command $cmd
	} else {
		& $cmd
	}
}