Skip to content

Instantly share code, notes, and snippets.

@jaywryan
Last active February 9, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaywryan/a7329c66729c0d8ef358054bed74ff37 to your computer and use it in GitHub Desktop.
Save jaywryan/a7329c66729c0d8ef358054bed74ff37 to your computer and use it in GitHub Desktop.
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