Skip to content

Commit

Permalink
Cleaned up Excel Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
DevClate committed Jan 28, 2024
1 parent 8dec871 commit 78eb833
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
20 changes: 13 additions & 7 deletions Functions/Public/Export-CT365ProdTeamstoExcel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ function Export-CT365ProdTeamsToExcel {
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateScript({
switch ($psitem){
{-not(([System.IO.Path]::GetExtension($psitem)) -match "(.xlsx)")}{
"Invalid file format: '$PSitem'. Use .xlsx"
$isValid = $false
$extension = [System.IO.Path]::GetExtension($_)
$directory = [System.IO.Path]::GetDirectoryName($_)

if ($extension -ne '.xlsx') {
throw "The file $_ is not an Excel file (.xlsx). Please specify a file with the .xlsx extension."
}
Default{
$true
elseif (-not (Test-Path -Path $directory -PathType Container)) {
throw "The directory $directory does not exist. Please specify a valid directory."
}
}
})]
else {
$isValid = $true
}
return $isValid
})]
[string]$FilePath,

[Parameter(Mandatory)]
Expand Down
30 changes: 15 additions & 15 deletions Functions/Public/Export-CT365ProdUserToExcel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ function Export-CT365ProdUserToExcel {
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateScript({
$isValid = $false
$extension = [System.IO.Path]::GetExtension($_)
$directory = [System.IO.Path]::GetDirectoryName($_)

if ($extension -ne '.xlsx') {
throw "The file $_ is not an Excel file (.xlsx). Please specify a file with the .xlsx extension."
}
elseif (-not (Test-Path -Path $directory -PathType Container)) {
throw "The directory $directory does not exist. Please specify a valid directory."
}
else {
$isValid = $true
}
return $isValid
})]
$isValid = $false
$extension = [System.IO.Path]::GetExtension($_)
$directory = [System.IO.Path]::GetDirectoryName($_)

if ($extension -ne '.xlsx') {
throw "The file $_ is not an Excel file (.xlsx). Please specify a file with the .xlsx extension."
}
elseif (-not (Test-Path -Path $directory -PathType Container)) {
throw "The directory $directory does not exist. Please specify a valid directory."
}
else {
$isValid = $true
}
return $isValid
})]
[string]$FilePath,

[Parameter()]
Expand Down

0 comments on commit 78eb833

Please sign in to comment.