Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. Function Get-MdtClipboard {
  2. <#
  3. .SYNOPSIS
  4. Obtains the contents of the clipboard.
  5. .DESCRIPTION
  6. Obtains the contents of the clipboard. By default, each line will be a separate object and blank lines will be omitted. Use the -SpreadSheet switch if you are copying a region from an excel sheet.
  7. .PARAMETER IncludeEmptyLines
  8. When returning an array of objects, ignore empty lines on the clipboard.
  9. .PARAMETER TextBlock
  10. Treat the clipboard as a single string. Default behavior is to return an array of objects delimited by linebreaks, a la Get-Content.
  11. Brief parameter description
  12. .PARAMETER SpreadSheet
  13. Parses the clipboard as a tab-delimited CSV file. This is the default format when copying data out of Excel. Unless the header parameter is used, the first line is treated as the column headers.
  14. .PARAMETER Header
  15. Specify text array to use as column headers when interpreting clipboard contents as a CSV.
  16. .EXAMPLE
  17. Get-MdtClipBoard -SpreadSheet -Header "Name","Email"
  18. Return the copied Excel cels as an array of objects, using a custom header to name the columns.
  19. #>
  20. [CmdletBinding()]
  21. Param(
  22. [switch]$IncludeEmptyLines,
  23. [switch][alias("Block","TB")]$TextBlock,
  24. [switch][alias("SS")]$SpreadSheet,
  25. [array]$Header
  26. )
  27. Begin {}
  28. Process {
  29. Add-Type -Assembly PresentationCore
  30. $out = [Windows.Clipboard]::GetText()
  31. IF (!($TextBlock)) {
  32. $out = $out -replace "`r", '' -split "`n"
  33. IF ($SpreadSheet) {
  34. IF ($header) {
  35. $Out = ConvertFrom-Csv $out -Delimiter "`t" -Header $header
  36. }
  37. ELSE {
  38. $Out = ConvertFrom-Csv $out -Delimiter "`t"
  39. }
  40. }
  41.  
  42. IF (!($IncludeEmptyLines)) {
  43. $out = $out -ne ''
  44. }
  45. }
  46. ELSEIF ($IncludeEmptyLines -or $SpreadSheet -or $header) {
  47. Write-Warning "In TextBlock mode, all other parameters are ignored."
  48. }
  49.  
  50. Write-Output $out
  51. }
  52. END {}
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement