diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 6651fd4..c9d77af 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -6,7 +6,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '7.1.3' + ModuleVersion = '7.2.0' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' @@ -78,7 +78,8 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Open-ExcelPackage', 'PieChart', 'Pivot', - 'Remove-Worksheet' + 'Read-Clipboard', + 'Remove-Worksheet', 'Select-Worksheet', 'Send-SQLDataToExcel', 'Set-CellStyle', diff --git a/Public/Read-Clipboard.ps1 b/Public/Read-Clipboard.ps1 new file mode 100644 index 0000000..2c3b380 --- /dev/null +++ b/Public/Read-Clipboard.ps1 @@ -0,0 +1,53 @@ +function Read-Clipboard { + <# + .SYNOPSIS + Read text from clipboard and pass to either ConvertFrom-Csv or ConvertFrom-Json. + Check out the how to video - https://youtu.be/dv2GOH5sbpA + + .DESCRIPTION + Read text from clipboard. It is tuned to read tab delimited data. It can read CSV or JSON + + .EXAMPLE + Read-Clipboard # delimter default is tab `t + + .EXAMPLE + Read-Clipboard -Delimiter ',' # Converts CSV + + .EXAMPLE + Read-Clipboard -AsJson # Converts JSON + + #> + param( + $Delimiter = "`t", + $Header, + [Switch]$AsJson + ) + + if ($IsWindows) { + $osInfo = Get-CimInstance -ClassName Win32_OperatingSystem + if ($osInfo.ProductType -eq 1) { + $clipboardData = Get-Clipboard -Raw + if ($AsJson) { + ConvertFrom-Json -InputObject $clipboardData + } + else { + $cvtParams = @{ + InputObject = $clipboardData + Delimiter = $Delimiter + } + + if ($Header) { + $cvtParams.Header = $Header + } + + ConvertFrom-Csv @cvtParams + } + } + else { + Write-Error "This command is only supported on the desktop." + } + } + else { + Write-Error "This function is only available on Windows desktop" + } +} \ No newline at end of file