Last active
February 9, 2018 19:22
-
-
Save jaywryan/a7329c66729c0d8ef358054bed74ff37 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
Function Get-ClipboardText() { | |
<# | |
.Synopsis | |
cmdlet to use the Windows Forms.TextBox for copy and paste | |
.DESCRIPTION | |
This receives text from the clipboard and can be sent through the | |
pipeline as a text string. Useful for piping computernames, or usernames | |
through to other cmdlets | |
.EXAMPLE | |
Get-ClipboardText | Get-ADComputer | |
This example gets a computername from the clipboard and pipes it to Get-ADComputer | |
#> | |
Add-Type -AssemblyName System.Windows.Forms | |
$tb = New-Object System.Windows.Forms.TextBox | |
$tb.Multiline = $true | |
$tb.Paste() | |
$tb.Text | |
} | |
Function Get-ClipboardTextToArray { | |
<# | |
.Synopsis | |
This takes a carriage return delimited list of items from the clipboard | |
and adds them to an array | |
.DESCRIPTION | |
This wraps the get-ClipboardText function and turns a list of items in | |
the clipboard to an array. Consider copying the contents of a text file to | |
the clipboard like the following | |
Comp1 | |
Comp2 | |
Comp3 | |
This cmdlet would turn that text into a 3 item array | |
.EXAMPLE | |
PS>$clip = Get-ClipboardTextToArray | |
PS>$clip | |
PS>$clip | |
Comp1 | |
Comp2 | |
Comp3 | |
#> | |
(Get-ClipboardText).split("`n").trim() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment