From e87a6bdaf5a3e8b89b12d2f9c4061c6f38ee466f Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 4 Jul 2019 12:16:44 -0400 Subject: [PATCH] Add extension test back in --- ImportExcel.psm1 | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 73f15a7..3074774 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -348,13 +348,22 @@ function Import-Excel { process { if ($path) { - # $Path = (Resolve-Path $Path).ProviderPath - $resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue) - if ($resolvedPath) { - $Path = $resolvedPath.ProviderPath - } - else { - throw "'$($Path)' file not found" + if (!$firstTimeThru) { + # '.xls$|.xlsx$|.xlsm$' + $extension = [System.IO.Path]::GetExtension($Path) + if ($extension -notmatch '.xlsx$|.xlsm$') { + throw "Import-Excel does not support reading this extension type $($extension)" + } + + # $Path = (Resolve-Path $Path).ProviderPath + $resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue) + if ($resolvedPath) { + $Path = $resolvedPath.ProviderPath + } + else { + throw "'$($Path)' file not found" + } + $firstTimeThru = $true } $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'