From 585d9686a60280195611009c72cc37eacdf544e7 Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 4 Jul 2019 16:14:36 -0400 Subject: [PATCH] Remove firstTimeThru check --- ImportExcel.psm1 | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 3074774..9d87bee 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -269,7 +269,6 @@ function Import-Excel { [Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] [Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] [Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )] - # [ValidateScript( { (Test-Path -Path $_ -PathType Leaf) -and ($_ -match '.xls$|.xlsx$|.xlsm$') })] [String]$Path, [Parameter(ParameterSetName = "PackageA", Mandatory)] [Parameter(ParameterSetName = "PackageB", Mandatory)] @@ -347,23 +346,17 @@ function Import-Excel { process { if ($path) { + $extension = [System.IO.Path]::GetExtension($Path) + if ($extension -notmatch '.xlsx$|.xlsm$') { + throw "Import-Excel does not support reading this extension type $($extension)" + } - 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 + $resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue) + if ($resolvedPath) { + $Path = $resolvedPath.ProviderPath + } + else { + throw "'$($Path)' file not found" } $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'