gangstanthony

Get-Clipboard.ps1

Apr 13th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://www.reddit.com/r/PowerShell/comments/4em3qe/is_it_possible_to_do_a_multiline_readhost_into_an/
  2.  
  3. <# http://stackoverflow.com/questions/34700427/quickly-create-a-list-of-strings
  4. Add-Type -Assembly System.Windows.Forms | Out-Null
  5. $clp = [Windows.Forms.Clipboard]::GetText() -split "`r`n"
  6. #>
  7.  
  8. # http://stackoverflow.com/questions/1567112/convert-keith-hills-powershell-get-clipboard-and-set-clipboard-to-a-psm1-script
  9. function Get-Clipboard {
  10.     [CmdletBinding(ConfirmImpact='None', SupportsShouldProcess=$false)] # to support -OutVariable and -Verbose
  11.     param ()
  12.  
  13.     Add-Type -AssemblyName System.Windows.Forms
  14.     if ([threading.thread]::CurrentThread.ApartmentState.ToString() -eq 'STA') {
  15.         Write-Verbose 'STA mode: Using [Windows.Forms.Clipboard] directly.'
  16.         # To be safe, we explicitly specify that Unicode (UTF-16) be used - older platforms may default to ANSI.
  17.         [System.Windows.Forms.Clipboard]::GetText([System.Windows.Forms.TextDataFormat]::UnicodeText)
  18.     } else {
  19.         Write-Verbose 'MTA mode: Using a [System.Windows.Forms.TextBox] instance for clipboard access.'
  20.         $tb = New-Object System.Windows.Forms.TextBox
  21.         $tb.Multiline = $true
  22.         $tb.Paste()
  23.         $tb.Text
  24.     }
  25. }
  26.  
  27. <# http://poshcode.org/2150
  28. function Get-Clipboard {
  29.     Set-StrictMode -Version Latest
  30.     PowerShell -NoProfile -STA -Command {
  31.         Add-Type -Assembly PresentationCore
  32.         [Windows.Clipboard]::GetText()
  33.     }
  34. }
  35. #>
  36.  
  37. <# http://stackoverflow.com/questions/1567112/convert-keith-hills-powershell-get-clipboard-and-set-clipboard-to-a-psm1-script
  38. function Get-ClipBoard {
  39.     Add-Type -AssemblyName System.Windows.Forms
  40.     $tb = New-Object System.Windows.Forms.TextBox
  41.     $tb.Multiline = $true
  42.     $tb.Paste()
  43.     $tb.Text
  44. }
  45. #>
Add Comment
Please, Sign In to add comment