Get-Clipboard

by Jun 27, 2011

If your PowerShell host uses the STA mode, you can easily read clipboard content like this:

function Get-Clipboard {
  if ($Host.Runspace.ApartmentState -eq 'STA') {
        Add-Type -Assembly PresentationCore
        [Windows.Clipboard]::GetText()
    } else {
    Write-Warning ('Run {0} with the -STA parameter to use this function' -f $Host.Name)
  }
}

 

Twitter This Tip!
ReTweet this Tip!