Add extension test back in

This commit is contained in:
dfinke
2019-07-04 12:16:44 -04:00
parent 5ded5111b4
commit e87a6bdaf5

View File

@@ -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'