Last active
March 8, 2019 18:28
-
-
Save Trucido/c0f0326f23f59a3677bcb0ea8959d2a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Get-Clipboard.ps1 - Gets clipboard content if content type is text. | |
Note: Conflicts/replaces Pscx\Get-Clipboard which doesn't work in powershell >= 6 | |
#> | |
function Get-ClipboardText([switch][Alias("S*","L*")]$SplitLF) { | |
Set-StrictMode -Version 'Latest' | |
if($SplitLF) { | |
# Note: Newline CRLF/CR/LF handling should be automatic, but just in case... | |
$cmd = { | |
Add-Type -Assembly PresentationCore | |
$content = [Windows.Clipboard]::GetText() | |
if ($content) { | |
$content -replace "`r", '' -split "`n" | |
} | |
} | |
} else { | |
$cmd = { | |
Add-Type -Assembly PresentationCore | |
$content = [Windows.Clipboard]::GetText() | |
if ($content) { | |
$content | |
} | |
} | |
} | |
if([threading.thread]::CurrentThread.GetApartmentState() -eq 'MTA' -or $PSEdition -eq 'Core') { | |
& powershell -Sta -NoProfile -NonInteractive -Command $cmd | |
} else { | |
& $cmd | |
} | |
} | |
if (!($MyInvocation.InvocationName -eq '.' -or $MyInvocation.Line -eq '')) | |
{ | |
Get-ClipboardText @args | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment